如果对象的数量大于 3,我UIPicker
的会崩溃,并出现以下错误:NSArray
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSAutoreleasePool pickerView:titleForRow:forComponent:]: 无法识别的选择器发送到实例
这是我的功能代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.glassPickerOptions = [[NSArray alloc] initWithObjects:@"3mm",@"4mm",@"DG4+4",@"DG4+6",nil];
[glassPicker setFrame:CGRectMake(0, 0, 320, 162)];
[glassPicker selectRow:1 inComponent:0 animated:NO];
}
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
NSInteger glassPickerOptionsCount = self.glassPickerOptions.count;
NSLog(@"%i", glassPickerOptionsCount);
return glassPickerOptionsCount;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return (NSString*) [self.glassPickerOptions objectAtIndex:row];
}
希望我没有错过任何东西。提前致谢