Question

I am sure this is probably an easy issue, but I am stumped. My app uses a few tableviews with custom tableviewcells to handle the cell UI. When I try to assign values to the cell with the fetchedresultscontroller's NSFetchedResultsChangeUpdate case, I run into the issue...

Normally, I would use something like this:

MyCustomTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

Only, the cellForRowAtIndexPath seems to want to return a UITabelViewCell, and not my custom cell... it's only a warning, but I am wondering why it is not working...

Here is the relevant code from the FRC...

-(void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
  atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
 newIndexPath:(NSIndexPath *)newIndexPath {

UITableView *tableView = self.tableView;

switch (type) {
    case NSFetchedResultsChangeUpdate: {
        MyCustomTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
...
//do stuff with the cell...
}
}
break;
}
}

And here is my cellForRowAtIndexPath method...

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

MyCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PlayerTableCell" forIndexPath:indexPath];
Player *player = [self.fetchedResultsController objectAtIndexPath:indexPath];

...
//cell configuration
...

return cell;
}
Was it helpful?

Solution

just force cast it into your subclass like this:

MyCustomTableViewCell *cell =(MyCustomTableViewCell *) [tableView cellForRowAtIndexPath:indexPath];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top