NSRangeException',原因:'*** - [__ NSArrayM objectAtIndex:]:索引5超出空数组的边界'

Rus*_*edi 9 objective-c uitableview ios

在我的应用程序中,当我第一次运行应用程序时,它工作正常.但是当我再次运行2次,它崩溃了.

这是错误..

NSRangeException',原因:'*** - [__ NSArrayM objectAtIndex:]:索引5超出空数组的边界'

在此输入图像描述

在此输入图像描述

Vij*_*com 18

原因:您正在访问要在索引处访问对象的Empty数组.

替换下面代码中的所有地方

[arrMydata objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)

 //1. Positive index ([anArray objectAtIndex:-NUMBERS]) will crash

 //2. within the array boundary

 if([arrMydata count] > 0 && [arrMydata count] > indexPath.row){

    shrObj=[arrMydata objectAtIndex:indexPath.row];

 }
 else{

    //Array is empty,handle as you needed

 }
Run Code Online (Sandbox Code Playgroud)

**这里您可以看到非软件示例,它将解释此问题.祝好运!**