【发布时间】:2014-03-18 05:08:59
【问题描述】:
我想清除我的数组,我所做的是,
我的应用中有 tableview 视图,首先我从服务器获取数据并将其加载到 tableView 中。
-(void)viewDidLoad{
//fetching data from server using background thread and storing it in array called (msg_array)
[table reloadData];
}
当最后一行出现在屏幕上时,我想从服务器获取新数据并显示它,
-(void)LoadMoreData{ //this method gets fire when last cell is on screen
if ([msg_array count]>0)
{
[msg_array removeAllObjects]; //crashes here
}
}
这给出了错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[__NSArrayI removeAllObjects]: unrecognized selector sent to instance
为什么会导致崩溃:
数组是这样分配的:
msg_array = [dictShow copy];
dictshow 包含数据并将其复制到 msg_array 并且 dictshow 是可变字典
(取自comments)
【问题讨论】:
-
是 msg_array NSArray 还是 NSMutableArray?因为 NSArray 没有一个名为 removeAllObjects 的方法。因此崩溃了。
标签: ios iphone objective-c ipad nsarray