DequeueReusableCellWithIdentifier does not return a cell of my custom type

I am using ios5 storyboards with a UITableViewController with a subclass of UITableViewCell. I do not want to create visual cell elements in the storyboard designer for presentation, because I want to use a reusable subclass of UITableViewCell (specifically TDBadgedCell ).

I set my cell id in the storyboard designer, and all the rows load correctly in the UITableView until I set any properties unique to TDBadgedCell. If I set the property badgeString, although this is unique to TDBadgedCell, I get an exception. I narrowed that it dequeueReusableCellWithIdentifier:does not return a cell of type TDBadgedCell.

I only work with UITableViewController. I have a UIViewController with a built-in UITableView configured in the same way and that is not a problem. Any ideas?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *CellIdentifier = @"PhoneNumberCell";
TDBadgedCell *cell = (TDBadgedCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

if ([cell isKindOfClass:[TDBadgedCell class]])
{
    NSLog(@"It is TDBadgedCell");
}
else
    NSLog(@"It is NOT TDBadgedCell");
+5
source share
3 answers

I had a similar problem in that I subclass UITableViewCell but don't use the storyboard. Here is my decision to use different cell classes, depending on whether the user has acquired the application unlock feature. Hope this helps someone.

In a nutshell, I had a cell with several objects, including a UITextView object. I wanted to block the copy and paste function of the UITextView object in the lite version, but then release this function after the user purchases the product in the application.

UITableViewCell: UITextView , UITextView, canBecomeFirstresponder, NO. , UITextview, .

, , , .

? [self.tableview reloadData] , . , . , .

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


if (your test if in-app was purchased is yes)
{
static NSString *MyIdentifier = @"MyCell";

FrontCell *cell = (FrontCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil)
        {
        cell = [[FrontCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.shouldIndentWhileEditing = NO;
    }

//....///     

cell.trackDetails.text = [yourObject objectAtIndex:indexPath.row];
cell.trackDetails.delegate = self;
cell.trackDetails.tag = indexPath.row;


return cell;
}
else // inapp not purchased
{
    static NSString *MyLockedIdentifier = @"MyLockedCell";

    FrontCellLocked *cell = (FrontCellLocked *)[tableView dequeueReusableCellWithIdentifier:MyLockedIdentifier];

    if (cell == nil)
    {
        cell = [[FrontCellLocked alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyLockedIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.shouldIndentWhileEditing = NO;
    }

     //....///     

cell.trackDetails.text = [yourObject objectAtIndex:indexPath.row];
cell.trackDetails.delegate = self;
cell.trackDetails.tag = indexPath.row;


return cell;    }
}
0

Custom Class UITablviewCell.
dequeueReusableCellWithIdentifier .

0

I think you are using the wrong method to delete objects.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self.tblProfileInfo dequeueReusableCellWithIdentifier:@"PostCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}

You forgot for indexPath at the end.

0
source

All Articles