加载UITableView时崩溃

时间:2011-05-27 19:40:27

标签: cocoa-touch ios ios4

我有一个UITableView,它从三个NSMutableArrays中加载数据:

  • 一个用户名
  • 一个用于实名
  • 一个用于图片

当加载一些项目时,它可以正常工作,但是当加载项目(推特粉丝)时它会崩溃说:

*** 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"
)

1 个答案:

答案 0 :(得分:4)

您尚未发布相关代码,但例外情况只是说在您对insertObject:atIndex:的调用中,您已将nil作为对象传递,这是不允许的。如果您想添加表示无值的值,则必须改为插入[NSNull null]