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. 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. 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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.