[英]NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array'
in my application when i run app for first time,it work ok.but when i run again 2 two times, it crashes.在我的应用程序中,当我第一次运行应用程序时,它工作正常。但是当我再次运行 2 次时,它崩溃了。
This is the error..这是错误..
NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds for empty array' NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]:索引 5 超出空数组的边界'
Reason: You are accessing Empty array about to access object at index.原因:您正在访问即将访问索引处的对象的空数组。
replace all places like in your code below替换下面代码中的所有位置
[arrMydata objectAtIndex:indexPath.row];
with和
//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!祝你好运! ** **
You array is empty, but you're trying to access an object in it.您的数组为空,但您正在尝试访问其中的对象。 That is the problem.那就是问题所在。
Reason: According to your log, you're trying to access empty array.原因:根据您的日志,您正在尝试访问空数组。 Just fix this by below code只需通过以下代码修复此问题
if (arrMydata.count > inxexPath.row)
sharObj = [arrMydata objectAtIndex:indexPath.row]
In case this helps someone : in my case the array was not in code, but an IB outlet that was an array of 5 UIImageViews in the storyboard.如果这对某人有帮助:在我的情况下,数组不在代码中,而是一个 IB 插座,它是故事板中 5 个 UIImageViews 的数组。
@IBOutlet var upAndDownArrowImages: [UIImageView]! @IBOutlet var upAndDownArrowImages:[UIImageView]!
Reason for the crash was that I mistakenly deleted 1 of those UIImageViews from the Storyboard.崩溃的原因是我错误地从 Storyboard 中删除了其中 1 个 UIImageViews。
In my case, it Crashes for heightForRowAt indexpath
, Do check this method for smooth operation.在我的情况下,它因heightForRowAt indexpath
崩溃,请检查此方法以确保顺利运行。
Hope it Helps someone.希望它可以帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.