我有一个方法,我用它滚动到我的collectionView的底部
- (void) scrollToBottom {
if (_messagesArray.count > 0) {
static NSInteger section = 0;
NSInteger item = [self collectionView:_myCollectionView numberOfItemsInSection:section] - 1;
if (item < 0) item = 0;
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForItem:item inSection:section];
[_myCollectionView scrollToItemAtIndexPath:lastIndexPath atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
而且效果很好!我从来没有遇到任何问题,它的工作方式是100%一致的...用模态视图演示.但是,如果我将viewController推送到导航控制器上,它就不起作用了.相反,只有超过15个单元格才有效.一旦我达到至少15个细胞,它再次开始表现完美.在15个单元格之前,它要么根本不滚动,要么滚动一点.
我意识到这是一个很长的镜头,但我在这个问题上摸不着头脑,我想也许有人可能知道发生了什么事.
故障排除:
你有登录以确保它正在运行吗?是
您是否已记录索引路径以确保其尝试滚动到正确的索引路径?是


我发现了问题。
由于某种原因,导航控制器会自动调整我的顶部内容插图。我可以通过添加以下内容来防止这种行为:
- (void) scrollToBottom {
if (_isNavigationControllerVersion) {
_myCollectionView.contentInset = UIEdgeInsetsZero;
}
if (_messagesArray.count > 0) {
static NSInteger section = 0;
NSInteger item = [self collectionView:_myCollectionView numberOfItemsInSection:section] - 1;
if (item < 0) item = 0;
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForItem:item inSection:section];
[_myCollectionView scrollToItemAtIndexPath:lastIndexPath atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7415 次 |
| 最近记录: |