我正试图修改一个多维数组中的值,但是却得到了编译错误:
warning: passing argument 2 of 'setValue:forKey:' makes pointer from integer without a cast
这是我的内容数组:
NSArray *tableContent = [[NSArray alloc] initWithObjects:
[[NSArray alloc] initWithObjects:@"a",@"b",@"c",nil],
[[NSArray alloc] initWithObjects:@"d",@"e",@"f",nil],
[[NSArray alloc] initWithObjects:@"g",@"h",@"i",nil],
nil];
这是我尝试更改值的方法:
[[tableContent objectAtIndex:0] setValue:@"new value" forKey:1];
解决方案:
[[tableContent objectAtIndex:0] setValue:@"new val" forKey:@"1"];
因此,数组键是字符串类型 - 这有点奇怪,但需要知道。
NSMutableArray
没有setObject:atIndex:
方法,而是使用replaceObjectAtIndex:withObject:
方法。请参考 http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html。 - dreamlax