저는 UITableView를 사용하고 셀을 추가했습니다.UITableView에서 잘못된 셀 내용을 표시합니다.
메시지를 표시하기 위해 UITableView를 기반으로하는 채팅 앱이 있습니다. 사용자가 이전 메시지로 채팅을 열면 모든 것이 잘 작동합니다. 그러나 사용자가 새 메시지를 추가하면 해당 메시지의 셀에 잘못된 내용이 채워집니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Im using storyboard, so I don't need if (!cell) part
RightMessageCell *cell = (RightMessageCell *) [self.messageTableView dequeueReusableCellWithIdentifier:@"right_text_message"];
[self configureCell:cell forIndexPath:indexPath];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
[self configureCell:self.offscreenCell forIndexPath:indexPath];
[self.offscreenCell setNeedsLayout];
[self.offscreenCell layoutIfNeeded];
result = [self.offscreenCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
}
- (void) configureCell:(RightMessageCell *) cell forIndexPath:(NSIndexPath *) indexPath {
ChatMessageModel *message = [self.fetchController objectAtIndexPath:indexPath];
rightMessageCell.messageTextView.text = message.messageText;
}
그리고 FRC 방법 :
내가 messages.Here를 표시하기위한 사용자 정의 셀을 사용 (간체) 내 코드입니다
#pragma mark - NSFetchedResultsControllerDelegate
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[self.messageTableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.messageTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationNone];
break;
case NSFetchedResultsChangeDelete:
[self.messageTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
break;
case NSFetchedResultsChangeUpdate:
[self.messageTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.messageTableView endUpdates];
}
그러나 새로 생성 된 세포가 오는 이유를 알아낼 수 없습니다 이전 셀 내용을 사용하고 다시 그릴 때 자신의 콘텐츠를 바꿉니다 (예 : 위아래로 스크롤 할 때)
실제 코드인가요? 'configureCell : ...'메소드에서'rightMessageCell'이란 무엇입니까? –
@MartinR 메시지 셀의 하위 클래스로, 텍스트를위한 콘센트 보유 messageTextView – user2786037
'RightMessageCell' 클래스가 아니라'rightMessageCell' 변수를 의미합니다. 그게'cell.messageTextView.text = ...'가 아니겠습니까? –