NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];NSArray *myArray = [NSArray arrayWithObject:indexPath];NSLog(@"count:%d",[myArray count]);[self.tableVIEw insertRowsAtIndexPaths:myArray withRowAnimation:UItableVIEwRowAnimationFade];[self.tableVIEw scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollposition:UItableVIEwScrollpositiontop animated:YES];
当它与模拟器一起运行时,我得到这个输出:
count:1
* Terminating app due to uncaught exception ‘NSRangeException’,reason: ‘* -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array’
这发生在[self.tableVIEw insertRowsAtIndexPaths:myArray withRowAnimation:UItableVIEwRowAnimationFade];但是,NSLog语句显示名为myArray的NSArray不为空.我错过了什么吗?以前有没有遇到过这个?
解决方法 在日志语句之前的行中,您将创建一个仅在此方法范围内有效的新数组.您用于表视图的数据源方法的数组是不同的,因此该数组中的对象数量根本不重要,即使它(我怀疑)具有相同的名称. 总结以上是内存溢出为你收集整理的objective-c – 在非空数组上获取’索引0超出空数组边界’错误全部内容,希望文章能够帮你解决objective-c – 在非空数组上获取’索引0超出空数组边界’错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)