【发布时间】:2019-01-08 21:18:39
【问题描述】:
下面的代码从NSMutableArray 中获取值,从一个对象中获取值,然后将它们添加到另一个NSMutableArray 中以供使用。我需要做的是为NSMutableArray *options 中的每个项目添加一个新行,但它会崩溃说:
[__NSSingleObjectArrayI 长度]: 无法识别的选择器发送到实例
如果我注释掉for (int i = 0; i < options.count; i++) 中的代码并留下NSLog(@"FIELD),它会显示正确的值。有什么想法吗?
LFFormSectionLabel *sectionLabel = [LFFormSectionLabel new];
[sectionLabel addValue:header forSEL:@selector(setText:)];
[vc addSection:sectionLabel];
NSMutableArray *options = [[NSMutableArray alloc] init];
for (NSDictionary *item in self.surveydata) {
NSString *addressfield = [item objectForKey:@"address_option"];
[options addObject:addressfield];
}
for (int i = 0; i < options.count; i++) {
NSString *field = [options objectAtIndex:i];
LFFormRowTextField *rowTextField = [LFFormRowTextField new];
rowTextField.key = @"name";
[rowTextField addValue:field forSEL:@selector(setPlaceholder:)];
[sectionLabel addRow:rowTextField];
NSLog(@"FIELD: %@", field);
}
【问题讨论】:
-
您需要提供有关
self.surveydata中内容的更多详细信息。但似乎[item objectForKey:@"address_option"]返回的是NSArray,而不是NSString。
标签: objective-c nsmutablearray nsdictionary