【发布时间】:2014-04-15 14:42:13
【问题描述】:
我想为某个键设置对象的值,但我收到了这个奇怪的错误。 我也尝试使用 setValue 代替 setObject 并且 routenArray2 也得到了其中的密钥。
NSMutableArray *routenArray = [[NSMutableArray alloc] init];
NSMutableArray *routenArray2 = [[NSMutableArray alloc] init];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
abfahrt,@"Abfahrt", ankunft, @"Ankunft", dauer, @"Dauer", route, @"Route", kennung, @"Kennung", nil];
[routenArray addObject:dict];
for (int j = 0; j < routenArray.count; j++) {
NSNumber *lNumber = [indexArray objectAtIndex:j];
int l = [lNumber intValue];
if (l == i) {
[routenArray2 addObject:[[routenArray objectAtIndex:j] copy]];
}
}
NSString *kennungString = [NSString stringWithFormat:@"%d", k];
for (int i = 0; i < routenArray2.count; i++) {
[[routenArray2 objectAtIndex:i] setObject:kennungString forKey:@"Kennung"]; //this line is the problem
}
【问题讨论】:
-
你得到更详细的错误是什么 - 你得到的日志?为什么我可以看到
k而看不到声明? -
'NSInvalidArgumentException',原因:'-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance' 这就是错误。 k 是一个整数
-
-1 表示未在原始问题中包含 exact and complete 错误消息,并且未识别失败的行。
-
@HotLicks 非常感谢。
-
不客气!这是一堂非常便宜的课。
标签: ios objective-c nsmutablearray nsmutabledictionary