UITableview中的UIPickerview

时间:2011-05-27 12:52:53

标签: iphone objective-c ipad uitableview uipickerview

我在UIPickerview和UITableview中遇到常见错误,即

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4d32080> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key CurrencyPicker.'

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4b2c070> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'

请帮助我为什么这些。

我认为这是由于tableview和picker视图的数据源和委托连接到文件所有者。但我做的每件事都做对了。

Plz帮助我。

感谢。

2 个答案:

答案 0 :(得分:0)

@Aman:这是代码:

@Aman:在setting.h中

@interface Setting : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>{
    UIButton *button;

    NSMutableArray *CurrencyArray;
    IBOutlet UIPickerView *CurrencyPicker;
}

在setting.m

- (void)viewDidLoad {
    [super viewDidLoad];

    CurrencyArray = [[NSMutableArray alloc] init];
    [CurrencyArray addObject:@" Rs "];
    [CurrencyArray addObject:@" R$ "];
    [CurrencyArray addObject:@" $ "];
    [CurrencyArray addObject:@" ƒ "];
    [CurrencyArray addObject:@" ман "];

    button=(UIButton *)[self.view viewWithTag:1];

    [CurrencyPicker selectRow:1 inComponent:0 animated:NO];
    [button setTitle:[CurrencyArray objectAtIndex:[CurrencyPicker selectedRowInComponent:0]] forState:UIControlStateNormal];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    return 1;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    [button setTitle:[CurrencyArray objectAtIndex:row] forState:UIControlStateNormal];
}

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

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

答案 1 :(得分:0)

我认为this帖子可以帮助你