简体   繁体   English

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

[英]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.

相关问题 'NSRangeException',原因:'* -[__NSArrayM objectAtIndex:]:索引 2 超出范围 [0 .. 1]' - 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]' 'NSRangeException',原因:'*** - [__ NSArrayM objectAtIndex:]:索引1超出边界[0 .. 0]' - 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]' 由于未捕获的异常'NSRangeException'终止应用程序,原因: - [__ NSArrayM objectAtIndex:]:索引0超出空数组的边界' - 2 - Terminating app due to uncaught exception 'NSRangeException', reason: -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' - 2 由于未捕获的异常'NSRangeException'终止应用程序,原因: - [__ NSArrayM objectAtIndex:]:索引0超出空数组的边界' - Terminating app due to uncaught exception 'NSRangeException', reason: -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' 由于未捕获的异常“ NSRangeException”而终止应用程序,原因:-[__ NSArrayM objectAtIndex:]:索引0超出了空数组的范围” - Terminating app due to uncaught exception 'NSRangeException', reason:-[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' NSRangeException',原因:'*** - [__ NSArrayM objectAtIndex:]:当呈现视图控制器时,索引0超出空数组的边界' - NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' when presenting view controller [__NSArrayM objectAtIndex:]:索引2超出空数组的范围 - [__NSArrayM objectAtIndex:]: index 2 beyond bounds for empty array [__NSArrayM objectAtIndex:]:空数组的索引0超出范围 - [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array 'NSRangeException',原因:'***-[__ NSArrayM objectAtIndexedSubscript:]:索引1超出范围[0 .. 0]' - 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 1 beyond bounds [0 .. 0]' UITableView 边界终止应用程序 'NSRangeException' -[__NSArrayM objectAtIndex:]: 索引 2 超出边界 [0 .. 1]' - UITableView bounds Terminating app 'NSRangeException' -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM