0

我正在将位置信息解析为NSMutableArray被调用的项目。我填写UIPickerView如下:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
return [items count];
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row     forComponent:(NSInteger)component {
return [items objectAtIndex:row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
  inComponent:(NSInteger)component
{
id item = [items objectAtIndex:row];
NSString *occasion = [item objectForKey:@"name"];
location.text = occasion;
}

当我这样做时,UIPickerView 中没有出现任何值,有人可以帮我解决这个问题吗?一切都正确连接

4

3 回答 3

2

像这样试试

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:    (NSInteger)component {
return [items count];
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row     forComponent:(NSInteger)component {
id item = [items objectAtIndex:row];
NSString *occasion = [item objectForKey:@"name"];
return occasion;
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
  inComponent:(NSInteger)component
{
id item = [items objectAtIndex:row];
NSString *occasion = [item objectForKey:@"name"];
location.text = occasion;
}

这将在选择器中显示字符串

还设置了pickerview的代表

我认为您正在传递整个字典而不是字符串

于 2013-02-22T11:30:29.190 回答
1

做这些事情:

#1 确保正确设置委托。例如。:

self.pickerView.delegate = self;

#2 检查你的场合字符串是否不为零也不为空。

NSLog(@"%@", occasion);
于 2013-02-22T10:53:50.740 回答
0

我猜项目数组可以是字典数组。因此,您应该在 NSDictionary 中获取 NSString。

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row     forComponent:(NSInteger)component {
return [[items objectForKey:@"name"] objectAtIndex:row];
}
于 2013-02-22T11:39:13.850 回答