【问题标题】:IOS [__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'IOS [__NSPlaceholderArray initWithObjects:count:]: 尝试从 objects[0] 插入 nil 对象'
【发布时间】:2013-04-28 05:44:26
【问题描述】:

我正在尝试创建像 facebook 这样的动态幻灯片菜单。

我必须从 json 请求中获取一些数据。并在幻灯片表视图的某个部分中显示此数据。 我是 Objective-c 的新手,我也尝试过使用 NSMutableArrays 并且出现错误。 在其他表格视图中,我做同样的事情,但没有部分。只有一个 MutableArray,我可以显示表格。

我会这样做:

-(void) requestJSONFinishedWithParsedObject:(NSDictionary *)parsedObject{


  NSArray  *projectsObjectArray = [parsedObject objectForKey:@"projects"];

    [self createMainNavigationController];
    self.section1 = [NSArray arrayWithObjects:@"Profile", @"Notifications", @"Exit", nil];
    self.section2 = [NSArray arrayWithObjects:@"Main", nil];


    for (NSDictionary *projectObject in projectsObjectArray)
    {
        Project *newProject = [[Project alloc] init];

        newProject.title= [projectObject objectForKey:@"title"];

        self.section3 = [NSArray arrayWithObject:newProject.title];
    }

    self.menu = [NSArray arrayWithObjects:self.section1, self.section2, self.section3, nil];
    [menuTableView reloadData];
}

我遇到了这个错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'

【问题讨论】:

  • NSLog(@"Val : %@",newProject.title);。输出是什么?

标签: ios uitableview nsarray tableview


【解决方案1】:

因为

newProject.title= [projectObject objectForKey:@"title"];

为零,您正尝试将其添加到数组中。通过记录来检查该值是什么

NSLog(@"%@", [projectObject objectForKey:@"title"]);

【讨论】:

    猜你喜欢
    • 2012-10-30
    • 2014-08-05
    • 1970-01-01
    • 2012-08-09
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    相关资源
    最近更新 更多