我用超类'UITableViewController'创建了一个'ToDoListTableViewController'类,并试图实现这段代码
[self configureCell:((ToDoTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath]) atIndexPath:indexPath];
但是我收到了这个问题标题中的错误。这是
中的完整方法- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
switch (type) {
case NSFetchedResultsChangeInsert:
{
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
case NSFetchedResultsChangeDelete:
{
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
case NSFetchedResultsChangeUpdate:
{
[self configureCell:((ToDoTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath]) atIndexPath:indexPath];
break;
}
case NSFetchedResultsChangeMove:
{
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
}
这是实现文件的开头
#import "ToDoListTableViewController.h"
#import <CoreData/CoreData.h>
#import "ToDoTableViewCell.h"
@interface ToDoListTableViewController ()<NSFetchedResultsControllerDelegate>
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@end
@implementation ToDoListTableViewController
在代码我在网上发现这个方法应该可以工作但是我收到了这个错误,有人可以帮我吗?
答案 0 :(得分:0)
您必须先创建方法configureCell:atIndexPath:
才能使用它!如果您正在关注在线教程,可能您忘了创建它。通常人们创建此方法以将单元属性的设置与单元本身的其余创建隔离开来。例如,当您尝试使用autolayout根据其内容计算单元格的高度时。