我有一个 UITableView,它从三个 NSMutableArrays 加载数据:
- 一个用于用户名
- 实名制
- 一张图片
当加载少量项目时它工作正常,但是当加载项目(Twitter 关注者)时它崩溃说我:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 2'
*** Call stack at first throw:
然后我去了它添加对象的地方并删除了代码,现在奇怪的是错误仍然存在! 我不知道现在在哪里可以找到 :( 提前致谢! 我将数据添加到数组的代码(在 MGTwitterEngine 方法上):
- (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier {
followers = [[NSMutableArray alloc] init];
followersname = [[NSMutableArray alloc] init];
followerspic = [[NSMutableArray alloc] init];
for(NSDictionary *d in userInfo) {
NSLog(@"See dictionary: %@", d);
NSString *user = [d objectForKey:@"screen_name"];
NSString *realname = [d objectForKey:@"name"];
NSString *pic = [d objectForKey:@"profile_image_url"];
[followers addObject:user];
[followersname addObject:user];
[followerspic addObject:user];
NSLog(@"%@", followers);
NSLog(@"%@", followersname);
NSLog(@"%@", followerspic);
}
[DSBezelActivityView removeViewAnimated:YES];
[self.tableView reloadData];
}
但是删除它仍然会报错:(
当数组是这样的:
2011-05-28 15:41:41.517 [10854:207] (
BeybladesOnline,
zad0xsis,
wesruca,
Carlyy6os9n
)
2011-05-28 15:41:41.517 [10854:207] (
"Beyblades Online",
"Pablo Merino",
"Antuan Gualker",
"Julissa Campbell"
)
2011-05-28 15:41:41.517 [10854:207] (
"http://a3.twimg.com/profile_images/1235933408/beyblades-thumb_normal.jpg",
"http://a2.twimg.com/profile_images/1371416207/ProfilePhoto_normal.png",
"http://a2.twimg.com/profile_images/1257535657/1129844554_b158a92a3a_normal.jpg",
"http://a1.twimg.com/sticky/default_profile_images/default_profile_0_normal.png"
)
最佳答案
你还没有发布有问题的代码,但异常只是说在你调用 insertObject:atIndex:
时,你传递了 nil
作为对象,它是不允许。如果你想添加一个表示没有值的值,你必须插入[NSNull null]
。
关于cocoa-touch - 加载 UITableView 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6156947/