5

例外:

在无效索引路径请求 rect

代码:

CGRect rect = [tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];

使固定:

if ([tableView numberOfRowsInSection:0] <= i) {
    return;
}

也许存在更好的方式

4

1 回答 1

3

通常 rectForRowAtIndexPath 可以将无效的 indexPath 处理为文档状态,但在 IOS 7.1 中,它不能正确处理无效的 indexPath。所以传入 nil 会导致崩溃并得到错误信息:

在无效索引路径({length = 2, path = 0 - 0})处请求 rect

总之,rectForRowAtIndexPath 需要手动进行 nil 检查。

于 2015-07-02T02:43:49.467 回答