UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃
来源:互联网 发布:怎么解锁windows驱动器 编辑:程序博客网 时间:2024/06/06 14:10
reason: '-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (0) beyond bounds (0) for section (0).
这个错误是传入的IndexPath已经越界了。需要在调用之前加入判断语句,不影响性能的情况下,在调用之前要先reloadDate
代码示例:
- (void)scrollToBottomAnimated:(BOOL)animated
{ if ([_messageList count] > 0 ) { NSInteger lastSectionIndex = [self.tableView numberOfSections] - 1; NSInteger lastRowIndex = [self.tableView numberOfRowsInSection:lastSectionIndex] - 1; if (lastSectionIndex > 0 && lastRowIndex > 0) { NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:lastRowIndex inSection:lastSectionIndex]; [self.tableView scrollToRowAtIndexPath:lastIndexPath atScrollPosition: UITableViewScrollPositionBottom animated:animated]; } }}
Update:
上面的代码有BUG,当section = 1时,永远不会滚动。当section = 0时,
[self.tableView numberOfRowsInSection:lastSectionIndex]
会有崩溃,正确代码段:
@implementation UITableView (ScrollToTopOrBottom)- (void)scrollToTopWithAnimated:(BOOL)animated{ if ([self numberOfSections] > 0 && [self numberOfRowsInSection:0] > 0) { [self scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:animated]; }}- (void)scrollToBottomWithAnimated:(BOOL)animated{ if ([self numberOfSections] > 0) { NSInteger lastSectionIndex = [self numberOfSections] - 1; NSInteger lastRowIndex = [self numberOfRowsInSection:lastSectionIndex] - 1; if (lastRowIndex > 0) { NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:lastRowIndex inSection:lastSectionIndex]; [self scrollToRowAtIndexPath:lastIndexPath atScrollPosition: UITableViewScrollPositionBottom animated:animated]; } }}@end
0 0
- UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃
- popToViewController:animated:的崩溃
- 即时聊天应在viewDidAppear发送scrollToRowAtIndexPath:atScrollPosition:animated滚动到最新一条记录
- tableviewcell动态高度和scrollToRowAtIndexPath:atScrollPosition:同用卡顿问题解决方案
- animated-rotate的用法
- About The Problem "scrollToItemAtIndexPath:atScrollPosition:animated:" doesn't work
- 关于UITableView的一个崩溃现象分析
- [self.tableView scrollToRowAtIndexPath:]方法滑动崩溃
- ReactNative Animated.view的用法
- UITableView处于编辑状态所在页面消失的时候崩溃
- UITableView删除的时候崩溃NSScanner:nil string argument
- /SourceCache/UIKit_Sim/UIKit-3347.44/UITableView.m:1623崩溃的原因
- iOS-分组UITableView删除崩溃问题(当删除section中最后一条数据崩溃的情况)
- iOS: UIScrollView的方法scrollRectToVisible:animated:
- iOS: UIScrollView的方法setContentOffset:animated:
- iOS: UIScrollView的方法setZoomScale:animated:
- iOS: UIScrollView的方法zoomToRect:animated:
- [Android] animated-rotate简单的转菊花...
- 手机下载wifiAPP,小心有wifi大盗!
- 归档Redis在Windows,linux平台下的安装配置【转
- XFire创建WebService实例
- 透过WebGL 3D看动画Easing函数本质
- 03_translation_saving key-value sets
- UITableView的scrollToRowAtIndexPath:atScrollPosition:animated的崩溃
- uml之类图
- 下一次全排列结果
- Unity3d通过Action注册事件,回调方法
- Java中读写Properties文件的工具类
- [ios]iOS学习之UITableView(一): 新手篇创建tableView
- 学习的方向和方法的总结
- codeforces The Wall - 题解
- 基于HTML5的燃气3D培训仿真系统