我UIPicker
崩潰,如果對象的NSArray
大於3,並出現以下錯誤:UIPicker崩潰
終止應用程序由於未捕獲的異常 '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];
}
希望我沒有錯過什麼。在此先感謝
是您UIPickerView設置爲包含pickerView班級的UIPickerViewDataSource和UIPickerViewDelegate網點:titleForRow:forComponent :?如果是這樣,看來你也許包含類pickerView:titleForRow:forComponent:被釋放(或者從不爲保留和過期的自動釋放池) –
這是我的接口聲明'@interface PickerView:的UIViewController '。這是作爲另一個ViewController的子視圖加載的。這個ViewController包含pickerView:titleForRow:forComponent:方法。 –
Leon