从Feed中填写UIPickerView

时间:2013-02-22 10:44:32

标签: iphone ios rss uipickerview

我正在将位置Feed解析为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中没有出现任何值,有人可以帮助我吗?一切都正确连接

3 个答案:

答案 0 :(得分: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的委托

我认为你传递整个字典而不是字符串可能

答案 1 :(得分:1)

做这些事情:

#1确保正确设置代理。例如。 :

self.pickerView.delegate = self;

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

NSLog(@"%@", occasion);

答案 2 :(得分:0)

我猜物品数组可以是字典数组。所以,你应该在NSDictionary中获得NSString。

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