Я добавляю строки в UITableView
с использованием метода insertRowsAtIndexPaths
. Я помещаю этот код между [myTable beginUpdates];
и [myTable endUpdates];
. Проблема в том, что моя таблица мигает, а затем прокручивается до последней строки?UITableView мигает, если я делаю insertRowsAtIndexPaths
В чем может быть проблема? Если я прокомментирую [myTable beginUpdates];
и [myTable endUpdates];
: тогда он отлично работает.
Спасибо заранее!
Вот мой код:
#pragma mark - NSFetchResultController
- (void)setFetchedResultsController:(NSFetchedResultsController*)fetchedResultsController
{
_fetchedResultsController = fetchedResultsController;
fetchedResultsController.delegate = self;
[fetchedResultsController performFetch:NULL];
}
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[tblComments beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
switch (type) {
case NSFetchedResultsChangeInsert: {
[tblComments insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
postUpdateScrollTarget = newIndexPath;
break;
}
case NSFetchedResultsChangeDelete: {
[tblComments deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
case NSFetchedResultsChangeUpdate: {
[self configureCell:(LFMCommentCell *)[tblComments cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
//[tblComments reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
case NSFetchedResultsChangeMove: {
[tblComments deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tblComments insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[tblComments endUpdates];
if (postUpdateScrollTarget)
{
[tblComments scrollToRowAtIndexPath:postUpdateScrollTarget atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
postUpdateScrollTarget = nil;
}
Вы можете поставить, пожалуйста, код между beginUpdates и endUpdates –
Любая идея @ Хамза GHAZOUANI – NSPratik
пожалуйста, вы можете добавить свой код в вопросе, в комментариях не lisible :) –