ios - NSRangeException',原因 : '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array'

标签 ios objective-c uitableview

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

这是错误..

NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]:索引 5 超出空数组的范围'

enter image description here

enter image description here

最佳答案

原因:您正在访问即将访问索引处对象的空数组。

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

[arrMydata objectAtIndex:indexPath.row];

 //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

 }

**Here You can see the non software example, which will explain this issue. Good luck! **

关于ios - NSRangeException',原因 : '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23423473/

相关文章:

ios - Sprite Kit - 无法从对象获取自定义类数据

javascript - Cordova In App Browser 事件未触发 IOS

iphone - 如何一键同时控制两个 UIScrollView?

ios - 无法滚动包含 UITextFields 的 UITableViewCells

iphone - 未收到 UIMoviePlayerControllerWillExitFullscreenNotification

iphone - StoreKit:我可以为用户提供他选择的通常收费的产品的免费下载吗?

ios - 尝试在Xcode Objective-C中创建按钮

ios - 在 appDelegate 中访问 Storyboard 和嵌套的 UIViewController

iphone - 自定义 UITableViewCell 创建两次......让我发疯

ios - NSURLConnection延迟导致没有图片的空UItableViewCell