0

可能重复:
此类与键的键值编码不兼容

当我在 XCode for iphone 中创建应用程序时,我遇到了此类问题。

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4d2eb20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key singlePicker.'
*** Call stack at first throw:
4

1 回答 1

0

您正在为NULLKey设置值

编辑:在您开始使用选择器之前,您需要:

在 .h 文件中:

UIViewController<UIPickerViewDelegate,UIPickerViewDataSource>{
 NSArray *array;
}

然后在 .m 文件中:

 -(void)viewDidload{ 
  [super viewDidload];

 array = [[NSArray alloc]initWithObjects:@"Lake",@"Diana",@"Jone",@"Alice",@"Byber",@"Nuces",nil]; 

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

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

 - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
 /*  do what you want if the picker selected  */


 }


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

 }
于 2012-07-16T10:00:55.240 回答