【问题标题】:iOS5: How to prevent exception for rectForRowAtIndexPath methodiOS5:如何防止 rectForRowAtIndexPath 方法出现异常
【发布时间】:2011-10-28 14:12:25
【问题描述】:

例外:

在无效索引路径处请求矩形

代码:

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

修复:

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

也许存在更好的方式

【问题讨论】:

    标签: exception ios5 tableview nsindexpath


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2010-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多