[英]How to keep UICollectionView always at the bottom while new data is inserted into core data store
I have a UICollectionView that uses an NSFetchedResultsController and I would like to have the view always scrolled at the bottom as new entries are inserted into the persistent store. 我有一个使用NSFetchedResultsController的UICollectionView,并且当新条目插入到持久性存储中时,我希望视图始终在底部滚动。 How would I do this?
我该怎么做? I have implemented the NSFetchedResultsController delegate methods and viewing the data in the collection works nice but I'm not sure how to implement this additional requirement.
我已经实现了NSFetchedResultsController委托方法,并且可以很好地查看集合中的数据,但是我不确定如何实现这一额外要求。 Suggestions?
有什么建议吗?
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[yourCollectionView reloadData];
CGRect lastCell = CGRectMake(0, CGFLOAT_MAX, 50, 50);
[yourCollectionView scrollRectToVisible:lastCell animated:YES];
//Or
/*
NSIndexPath *lastRow = [NSIndexPath indexPathForItem:yourItem inSection:yourSection];
[collectionView scrollToItemAtIndexPath:lastRow
atScrollPosition:UICollectionViewScrollPositionBottom
animated:NO];
*/
}
Try 尝试
-(void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated;
This will serve your purpose. 这将达到您的目的。
You actually need to do three things: 您实际上需要做三件事:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.