0

如果对象的数量大于 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];
}

希望我没有错过任何东西。提前致谢

4

1 回答 1

0

似乎您过度释放您的选择器视图,您可以看到这一点,因为消息被发送到自动释放池而不是您期望的对象,您应该检查您的选择器的保留/释放,看看发生了什么,不能从代码发布...

于 2011-09-29T21:40:59.173 回答