Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何防止在这种情况下发生-[\uu NSArrayM objectAtIndex:]::索引1越界[0..0]崩溃_Ios_Arrays_Uitableview_Crash - Fatal编程技术网

Ios 如何防止在这种情况下发生-[\uu NSArrayM objectAtIndex:]::索引1越界[0..0]崩溃

Ios 如何防止在这种情况下发生-[\uu NSArrayM objectAtIndex:]::索引1越界[0..0]崩溃,ios,arrays,uitableview,crash,Ios,Arrays,Uitableview,Crash,这是我的应用程序崩溃的原因。关于如何防止撞车事故的发生,是否有任何提示或建议。如果索引超出数组,则可能根本不执行这段代码。您不能保证indexPathForRowAtPoint:将返回有效的索引路径,因此请在使用它之前验证它: UITableViewCell* cell=[_tableView cellForRowAtIndexPath:[_tableView indexPathForRowAtPoint:point]]; 将代码分成两行。检查indexPathForRowAtPoint的返回

这是我的应用程序崩溃的原因。关于如何防止撞车事故的发生,是否有任何提示或建议。如果索引超出数组,则可能根本不执行这段代码。

您不能保证indexPathForRowAtPoint:将返回有效的索引路径,因此请在使用它之前验证它:

UITableViewCell* cell=[_tableView cellForRowAtIndexPath:[_tableView indexPathForRowAtPoint:point]];

将代码分成两行。检查indexPathForRowAtPoint的返回值。我在想,如果该点不可见,会发生什么?
NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:point];
if (indexPath) {
    UITableViewCell* cell=[_tableView cellForRowAtIndexPath:indexPath];
}