objective-c – 在非空数组上获取’索引0超出空数组边界’错误

objective-c – 在非空数组上获取’索引0超出空数组边界’错误,第1张

概述我有这个代码在我的应用程序的根视图控制器中向表视图添加一行: NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];NSArray *myArray = [NSArray arrayWithObject:indexPath];NSLog(@"count:%d", [myArray count]);[se 我有这个代码在我的应用程序的根视图控制器中向表视图添加一行:

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超出空数组边界’错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1225658.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存