我在核心数据中有数千行数据。取这么大的数据会明显减慢用户体验。因为我让用户以不同的方式查看数据,重新加载是常见的,重新加载FRC可能会很痛苦。因此,我一直在我的取款上限是50英镑。50对于速度来说是很好的,但它只提取了一小部分行,因此旧数据根本无法访问。
我想实现一个无限滚动,这样当用户点击tableview的底部时,就会加载新的行。我可以使用多个委托方法中的任何一个来触发重载,例如:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger lastSectionIndex = [tableView numberOfSections] - 1;
NSInteger lastRowIndex = [tableView numberOfRowsInSection:lastSectionIndex] - 1;
if ((indexPath.section == lastSectionIndex) && (indexPath.row == lastRowIndex)) {
// This is the last cell
[self getMore];
}
}
我的问题是用什么来得到更多。下面的方法很有效,但看起来很笨拙,因为需要重新加载所有先前的单元格,并且很难跟踪fetchlimit中的位置。有没有更有效的方法来完成无限卷轴?
- (void)getMore {
[self.fetchedResultsController.fetchRequest setFetchLimit:newFetchLimit];
self.fetchedResultsController = nil;
NSError *error;
if (![self.fetchedResultsController performFetch:&error]) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
[self.tableView reloadData];
}