當我嘗試向dataArray
添加新對象時出現錯誤。這是我如何定義dataArray
。對象不能爲零錯誤
-(NSMutableArray *)dataArray{
if (!_dataArray){
_dataArray = [[NSMutableArray alloc] initWithObjects:
[NSMutableArray arrayWithObjects:
[NSMutableArray array],
[NSMutableArray array],
[NSMutableArray array],
nil],
[NSMutableArray arrayWithObjects:
[NSMutableArray array],
[NSMutableArray array],
[NSMutableArray array],
nil],
nil];
}
return _dataArray;
}
這是我嘗試將對象添加到dataArray
:
[[[self.dataArray objectAtIndex:0] objectAtIndex:0] addObject:[NSString stringWithFormat:@"%@ %@",[attributeDict objectForKey:@"material"], [attributeDict objectForKey:@"tool"]]];
[[[self.dataArray objectAtIndex:0] objectAtIndex:1] addObject:[attributeDict objectForKey:@"level"]];
[[[self.dataArray objectAtIndex:0] objectAtIndex:2] addObject:[attributeDict objectForKey:@"probability"]];
這裏是我得到的錯誤:*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
爲什麼會出現這個錯誤,我該如何解決它?
您需要提供關於'attributeDict'的信息。我的猜測是'[attributeDict objectForKey:]'調用中的一個返回nil? – barley 2012-01-10 00:58:27
這添加3個對象,一次一個。哪個語句導致錯誤? [self.dataArray objectAtIndex:0]返回什麼? – 2012-01-10 01:21:22