테이블 뷰가 있고 NSFetchedResultsController를 사용하여 코어 데이터에 연결합니다. 나는 updateCellAtIndexPath
이라는 방법을 가지고 있는데, 셀 텍스트 레이블을 업데이트하는 데 사용하고 있습니다. 이 방법은 tableView:cellForRowAtIndexPath:indexPath
에서 호출합니다. 그건 잘 작동합니다. 내가 핵심 데이터 개체를 업데이트 할 때 NSFetchedResultsChangeUpdate 이후에 셀 내부의 값을 업데이트하십시오.
-(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를 받고 난
updateCellAtIndexPath
를 호출합니다. 문제는 셀 텍스트 레이블이 실제 값으로 올바르게 업데이트되지 않는다는 것입니다. 모든 것이 내가
updateCellAtIndexPath
-(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:
에하지만 reloadRowsAtIndexPaths:withRowAnimation:
설명서를 읽을 때, 그것은 그냥 값을 업데이트 할 경우, 나는이 방법을 사용하지 않도록 말한다 변경하면 작동하기 때문에 나는, 셀이 다시로드되지 않은 생각 :
셀의 값이 변경되었다는 것을 사용자에게 알리려면이 방법을 호출하십시오. 그러나 사용자에게 알리는 것이 이 아니라면 셀이 인 값을 변경하려는 것입니다. 특정 행의 셀을 가져 와서 새 값인 값을 설정할 수 있습니다.
왜 updateCellAtIndexPath
을 사용하여 셀 텍스트 레이블을 업데이트 할 수 없습니까?
안녕하세요 마틴, 나는 다른 XIB 및 클래스 및 기본 클래스를 모두 상속받은 셀이 들어오는, 나가는, 미디어, 오디오, 위치 셀 같이 하위 클래스 셀 : 메시지 셀. –