每对的第二个对象必须是非零的。或者,你忘记了 nil-terminate 你的参数列表吗?添加行数时
second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?' when adding row count
我遇到异常:
'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?'
在此代码中:
if ([[questionaireDic objectForKey:@"Answer6Option"] boolValue]) {
NSArray *ans6Arr = [subQuestionaireArr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"QuestionNo = 6 AND SortOrder = 1"]];
int rowCount = 1;
for (int i =0;i<ans6Arr.count ; i++) {
NSDictionary *ans6Dic = ans6Arr[ i];
NSDictionary *answer6Row1Cell1TextDic = [NSDictionary dictionaryWithObjectsAndKeys:@"810-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell1Text"],@"Value", nil];
[questionaireArr addObject:answer6Row1Cell1TextDic];
NSDictionary *answer6Row1Cell2DateDic = [NSDictionary dictionaryWithObjectsAndKeys:@"820-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell2Date"],@"Value", nil];
[questionaireArr addObject:answer6Row1Cell2DateDic];
NSDictionary *answer6Row1Cell3NumberDic = [NSDictionary dictionaryWithObjectsAndKeys:@"830-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell3Number"],@"Value", nil];
[questionaireArr addObject:answer6Row1Cell3NumberDic];
if (![[ans6Dic objectForKey:@"Cell4Number"] isKindOfClass:[NSNull class]]) {
NSDictionary *answer6Row1Cell4NumberDic = [NSDictionary dictionaryWithObjectsAndKeys:@"840-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell4Number"],@"Value", nil];
[questionaireArr addObject:answer6Row1Cell4NumberDic];
}
rowCount++;
}
我已经尝试了 Second object of each pair must be non-nil and Second object of each pair must be non-nil 中的修复程序。其中有几个 examples.But none 帮助了
我发现重新格式化代码以提高易读性有时会有所帮助...
如果您更改此行:
NSDictionary *answer6Row1Cell1TextDic = [NSDictionary dictionaryWithObjectsAndKeys:@"810-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell1Text"],@"Value", nil];
至:
NSDictionary *answer6Row1Cell1TextDic =
[NSDictionary dictionaryWithObjectsAndKeys:
@"810-L50-%d", rowCount,
@"DataId", [ans6Dic objectForKey:@"Cell1Text"],
@"Value", nil
];
您会看到您有一个对象 "Value"
的 nil
键...我敢肯定,这不是您的意图。
注意:我认为您的对象和键也颠倒了...
此异常是由于带有格式说明符的字符串引起的。您应该将两个 @"810-L50-%d",rowCount 值包含在一个字符串中。否则,它将 @"810-L50-%d" 作为键 rowCount.
的对象值
因此,键和值应更改为
NSDictionary *answer6Row1Cell1TextDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"810-L50-%d",rowCount], @"DataId",[ans6Dic objectForKey:@"Cell1Text"],@"Value", nil];
您似乎在尝试从格式 @810-L50-%d
和值 rowCount
生成字符串 * 而实际上并未调用字符串格式化方法来执行此操作。因此,您的值和键列表不同步,编译器报告与 nil
.
有关的错误
切换到现代语法并更正此问题:
NSDictionary *answer6Row1Cell1TextDic =
@{ @"DataId" : [NSString stringWithFormat:@"810-L50-%d",rowCount],
@"Value" : ans6Dic[@"Cell1Text"]
};
@{ ... }
语法是一个 字典文字 并且包含零个或多个 <key> : <value>
对。 ans6Dic[@"Cell1Text"]
是 字典索引,它查找与键匹配的值。
HTH
我遇到异常:
'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?'
在此代码中:
if ([[questionaireDic objectForKey:@"Answer6Option"] boolValue]) {
NSArray *ans6Arr = [subQuestionaireArr filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"QuestionNo = 6 AND SortOrder = 1"]];
int rowCount = 1;
for (int i =0;i<ans6Arr.count ; i++) {
NSDictionary *ans6Dic = ans6Arr[ i];
NSDictionary *answer6Row1Cell1TextDic = [NSDictionary dictionaryWithObjectsAndKeys:@"810-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell1Text"],@"Value", nil];
[questionaireArr addObject:answer6Row1Cell1TextDic];
NSDictionary *answer6Row1Cell2DateDic = [NSDictionary dictionaryWithObjectsAndKeys:@"820-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell2Date"],@"Value", nil];
[questionaireArr addObject:answer6Row1Cell2DateDic];
NSDictionary *answer6Row1Cell3NumberDic = [NSDictionary dictionaryWithObjectsAndKeys:@"830-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell3Number"],@"Value", nil];
[questionaireArr addObject:answer6Row1Cell3NumberDic];
if (![[ans6Dic objectForKey:@"Cell4Number"] isKindOfClass:[NSNull class]]) {
NSDictionary *answer6Row1Cell4NumberDic = [NSDictionary dictionaryWithObjectsAndKeys:@"840-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell4Number"],@"Value", nil];
[questionaireArr addObject:answer6Row1Cell4NumberDic];
}
rowCount++;
}
我已经尝试了 Second object of each pair must be non-nil and Second object of each pair must be non-nil 中的修复程序。其中有几个 examples.But none 帮助了
我发现重新格式化代码以提高易读性有时会有所帮助...
如果您更改此行:
NSDictionary *answer6Row1Cell1TextDic = [NSDictionary dictionaryWithObjectsAndKeys:@"810-L50-%d",rowCount,@"DataId",[ans6Dic objectForKey:@"Cell1Text"],@"Value", nil];
至:
NSDictionary *answer6Row1Cell1TextDic =
[NSDictionary dictionaryWithObjectsAndKeys:
@"810-L50-%d", rowCount,
@"DataId", [ans6Dic objectForKey:@"Cell1Text"],
@"Value", nil
];
您会看到您有一个对象 "Value"
的 nil
键...我敢肯定,这不是您的意图。
注意:我认为您的对象和键也颠倒了...
此异常是由于带有格式说明符的字符串引起的。您应该将两个 @"810-L50-%d",rowCount 值包含在一个字符串中。否则,它将 @"810-L50-%d" 作为键 rowCount.
的对象值因此,键和值应更改为
NSDictionary *answer6Row1Cell1TextDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"810-L50-%d",rowCount], @"DataId",[ans6Dic objectForKey:@"Cell1Text"],@"Value", nil];
您似乎在尝试从格式 @810-L50-%d
和值 rowCount
生成字符串 * 而实际上并未调用字符串格式化方法来执行此操作。因此,您的值和键列表不同步,编译器报告与 nil
.
切换到现代语法并更正此问题:
NSDictionary *answer6Row1Cell1TextDic =
@{ @"DataId" : [NSString stringWithFormat:@"810-L50-%d",rowCount],
@"Value" : ans6Dic[@"Cell1Text"]
};
@{ ... }
语法是一个 字典文字 并且包含零个或多个 <key> : <value>
对。 ans6Dic[@"Cell1Text"]
是 字典索引,它查找与键匹配的值。
HTH