Objective c NSFetchedResultsChangeUpdate后更新单元格内的值
我有一个tableview,我使用NSFetchedResultsController将其链接到核心数据。我有一个更新单元格文本标签的方法Objective c NSFetchedResultsChangeUpdate后更新单元格内的值,objective-c,uitableview,core-data,nsfetchedresultscontroller,Objective C,Uitableview,Core Data,Nsfetchedresultscontroller,我有一个tableview,我使用NSFetchedResultsController将其链接到核心数据。我有一个更新单元格文本标签的方法updatecellatindepath。我从tableView:cellforrowatinexpath:indepath调用此方法。那很好 -(UITableViewCell *)updateCellAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"
updatecellatindepath
。我从tableView:cellforrowatinexpath:indepath
调用此方法。那很好
-(UITableViewCell *)updateCellAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TripCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Trip *trip = [_controller objectAtIndexPath:indexPath];
cell.textLabel.text= [NSString stringWithFormat:@"%@" ,trip.name ];
return cell;
}
当我更新核心数据对象时,我收到NSFetchedResultsChangeUpdate,并调用updateCellationXPath
。问题是单元格文本标签未正确更新为实际值。我认为单元格没有重新加载,因为如果我将updateCellaIndeXPath
更改为reloadrowSatineXPaths:withRowAnimation:
-(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
{
switch (type){
case NSFetchedResultsChangeUpdate:
// works [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
// not works [self updateCellAtIndexPath:indexPath];
break;
default:
break;
}
}
但是,当我阅读reloadRowsAtIndexPaths:withRowAnimation:
的文档时,它说如果我只想更新值,就不应该使用此方法:
如果要提醒用户
细胞在变化。但是,如果没有通知用户
重要的是,您只需要更改单元格的值
显示可以获取特定行的单元格并设置其新值
价值观
那么,为什么我不能仅使用
updateCellatineXPath
更新单元格文本标签呢 您的updateCellatingXPath:
方法创建一个新单元格,而不是更新现有单元格。
如果从cellForRowAtIndexPath
调用,这是可以的,但从FRC调用时则不行
委托方法
如果您实施并使用“标准”,它应该会起作用
您可以在使用(主详细信息+核心数据)创建新应用程序时找到
Xcode中的模板。你好,Martin,我有一个单元格,它是用不同的XIB和类创建的,所有这些都继承了基类MessageCell,子类单元格为传入、传出、媒体、音频、位置单元格:Message Cell。
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath