繁体   English   中英

UIPicker 视图和 UITable 视图

[英]UIPicker view and UITable view

我在 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.'

请帮我解释为什么会这样。

我认为这是由于表视图和选择器视图与文件所有者的数据源和委托连接。 但我做的每一件事都是正确的。

请帮帮我。

谢谢。

@Aman:这是代码:

@阿曼:在setting.h

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

    NSMutableArray *CurrencyArray;
    IBOutlet UIPickerView *CurrencyPicker;
}

在设置.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];
}

我认为这篇文章可以帮助你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM