我确信这可能是一个容易的问题,但我很难过。我的应用程序使用一些带有自定义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;
}
答案 0 :(得分:0)
只需将它强制转换为子类,如下所示:
MyCustomTableViewCell *cell =(MyCustomTableViewCell *) [tableView cellForRowAtIndexPath:indexPath];