我正在研究 UIPickerView。我可以使用以下代码绑定并获取选定的值
pickerItems = [[NSArray alloc] initWithObjects:
[[[Company alloc] initWithName:@"Alabama" value:@"AL"] autorelease],
[[[Company alloc] initWithName:@"Alaska" value:@"AK" ] autorelease],
[[[Company alloc] initWithName:@"Arizona" value:@"AZ"] autorelease],
[[[Company alloc] initWithName:@"California" value:@"CA"] autorelease],
[[[Company alloc] initWithName:@"Wyoming" value:@"WY"] autorelease], nil];
但我正在使用一个网络服务,从中获取密钥和价值。我希望他们使用带有键和值的循环进行绑定。
如果我使用下面的代码,我会收到异常'线程 1:程序接收信号:“EXC_BAD_ACCESS”'
NSMutableArray *restArray = [[NSMutableArray alloc] initWithCapacity:5];
for (int i = 0; i <= 5; i++) {
NSString *key = [NSString stringWithFormat:@" Company %d ", i];
NSString *val = [NSString stringWithFormat:@" Company %d ", i];
Company *rest = [[Company alloc] initWithName:key value:val];
NSLog(@"restArray=%@ (%@)", restArray, NSStringFromClass([restArray class]));
[restArray addObject:rest];
[rest release];
}
pickerItems = restArray;
[restArray release];
提前致谢。