从fetchedresultscontroller引用子类tableviewcell?

时间:2014-05-12 20:58:01

标签: ios uitableview nsfetchedresultscontroller

我确信这可能是一个容易的问题,但我很难过。我的应用程序使用一些带有自定义tableviewcells的tableviews来处理单元格UI。当我尝试使用fetchedresultscontroller的NSFetchedResultsChangeUpdate案例为单元格赋值时,我遇到了问题......

通常,我会使用这样的东西:

MyCustomTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

只有,cellForRowAtIndexPath似乎想要返回一个UITabelViewCell,而不是我的自定义单元格... 这只是一个警告,但我想知道它为什么不起作用......

以下是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;
}
}

这是我的cellForRowAtIndexPath方法......

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

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

...
//cell configuration
...

return cell;
}

1 个答案:

答案 0 :(得分:0)

只需将它强制转换为子类,如下所示:

MyCustomTableViewCell *cell =(MyCustomTableViewCell *) [tableView cellForRowAtIndexPath:indexPath];