清除 NSMutableArray 以进行刷新
我有几个 NSMutableArrays
,刷新视图时需要清除它们。但是,当我尝试使用 [array removeAllObjects];
清除它们时,我的 tableview 由于索引超出界限错误
而崩溃。我对刷新所做的只是清除数组并调用与 viewDidLoad 中相同的函数来填充表格视图。 [tableView reloadData]
直到该方法的最后一行才会被调用。
编辑:问题很可能是这样的:我使用拉动来刷新外部库,当您向上滚动并释放表格时,它会向下弹回,因此 UITableView 尝试加载下一个单元格,但它无法加载下一个单元格,因为数组已清除,并且仍在加载。
答案:从数组中删除AllObjects,立即执行self.tableView reloadData,然后继续其余操作。
I have a couple of NSMutableArrays
which i need to clear when refreshing the view. However, when I try to clear them with [array removeAllObjects];
my tableview crashes due to index beyond bounds error
. All i do with the refresh, is clear the arrays and call the same function as in viewDidLoad for filling the tableview. [tableView reloadData]
doesn't get called until the very last line of the method.
EDIT: It's highly likely that the issue is this: I use a pull to refresh external lib, and when you scroll up and release the table, it bounces back down and thus the UITableView tries to load the next cell, which it cant because the array is cleared, and it's still being loaded.
Answer: removeAllObjects from the arrays, immediately do a self.tableView reloadData and then continue with the rest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
问题可能是由于
numberOfRowsInSection
返回一些计数而您的数据源数组为空。只需调用
[array removeAllObjects]
并在numberOfRowsInSection
中返回[array count]
。我希望它能解决您的问题。祝你好运!!!
problem might be due to
numberOfRowsInSection
returning some count and your data source array is empty.just call
[array removeAllObjects]
and innumberOfRowsInSection
return [array count]
.I hope it will resolve your issue. Best of Luck!!!
我通过以下方式从表格视图中删除单元格 -
I delete cells from my table view in the following manner-
当您刷新数组时,首先检查它是否有该对象&然后重新初始化您的阵列并释放一个。
When you refresh your array, first check if it has the object or not & then reinitialize your array and release one.
我所做的是
然后打电话
What i did was
then call