我有一個由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