Bri*_*ian 6 iphone scroll uitableview
在我的应用程序中,我尝试在更新表格内容后将UITableView滚动到顶部一次.但是,在某些情况下,我的桌子是EMPTY.所以我得到以下异常:
由于未捕获的异常'NSRangeException'终止应用程序,原因:' - [UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]:row(0)超出bounds(0)的section(0).
我怎么能抓住这个例外?我试过了
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
if (indexPath != nil) {
[EventTable scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
但它没有捕获异常,因为indexPath不是nil.
Tom*_*m S 12
在滚动到IndexPath之前,请检查UITableView以确保您尝试滚动到的行和部分分别小于表中的行数和部分数.如果是这样,请不要尝试滚动到该IndexPath.
if ( [tableView numberOfSections] < section || [tableView numberOfRowsInSection] < row )
Run Code Online (Sandbox Code Playgroud)
异常处理采用与典型流控制表达式不同的路径.Apple撰写了一篇关于Objective-C异常处理的有用文章.基本上你会想要将你的代码包装在@try/ @catchblocks中.它位于@catch您将收到异常的块中,并在您的代码中执行相应的后续步骤.
| 归档时间: |
|
| 查看次数: |
7316 次 |
| 最近记录: |