我有一个由NSFetchedResultsController驱动的UITableView。我调用了一种方法来创建一个NSPredicate,用于过滤自今天起拥有时间戳的实体。在我的NSFetchedResultsController中,我应用谓词。NSFetchedResultsController刷新UITableView条目没有重新加载口吃
if (appDelegate.displayTodayOnly) {
[fetchRequest setPredicate:datePredicate];
}
这一切都很好。但是,偶尔我需要查看“今天”之前的条目。我在桌子视图上向下滑动,当它已经在桌子的开始处时。
-(void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (self.tableView.contentOffset.y<0) {
if (appDelegate.displayTodayOnly) {
[appDelegate setDisplayTodayOnly:NO];
NSInteger resultsOffset = [[self.fetchedResultsController fetchedObjects] count];
//[self.tableView beginUpdates];
[__fetchedResultsController release];
__fetchedResultsController=nil;
NSError *error;
if (![[self fetchedResultsController] performFetch:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
//[self.tableView endUpdates];
NSInteger fullCount = [[self.fetchedResultsController fetchedObjects] count];
if (fullCount>resultsOffset) {
NSUInteger sect = [[self.fetchedResultsController sections] count]-2;
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:sect];
NSUInteger rows = [sectionInfo numberOfObjects]-1;
NSIndexPath *indexing = [NSIndexPath indexPathForRow:rows inSection:sect];
NSLog(@"IndexPath = section:%d row:%d",sect,rows);
[self.tableView reloadData];
[self performSelector:@selector(scrollToIndexPath:) withObject:indexing afterDelay:0.0001];
}
}
}
}
这也适用,但不雅。它放弃fetchedResultsController,并从条目开始的时间开始重新加载表。然后,我将它滚动到上一个表的条目上方的索引路径。
我想要发生的是要在当前表的顶部之前加载和插入条目。有谁知道一个优雅的方式来改变提取的发生?
是的,它的工作,这是我的scrollViewDidEndDragging方法发生了什么。我试图了解是否可能有一种方法来减轻重新加载,所以结果不会跳来跳去。 – JacobFennell 2012-02-07 16:49:12