Exception iOS5:如何防止RectforRowatineXpath方法出现异常

Exception iOS5:如何防止RectforRowatineXpath方法出现异常,exception,ios5,tableview,nsindexpath,Exception,Ios5,Tableview,Nsindexpath,例外情况: 在无效索引路径处请求rect 代码: 修正: 如果([tableView numberOfRowsInSection:0]通常rectForRowAtIndexPath可以将无效的indexPath作为文档状态处理,但在IOS 7.1中,它不能正确处理无效的indexPath。因此,传入nil将导致崩溃并获取错误消息: 在无效索引路径处请求rect( {length=2,path=0-0}) 总之,对于rectforrowatinexpath,手动执行nil检查是必要的 CGRect

例外情况:

在无效索引路径处请求rect

代码:

修正:


如果([tableView numberOfRowsInSection:0]通常rectForRowAtIndexPath可以将无效的indexPath作为文档状态处理,但在IOS 7.1中,它不能正确处理无效的indexPath。因此,传入nil将导致崩溃并获取错误消息:

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

总之,对于rectforrowatinexpath,手动执行nil检查是必要的

CGRect rect = [tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
if ([tableView numberOfRowsInSection:0] <= i) {
    return;
}