2011-09-29 39 views
0

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]; 
} 

希望我沒有錯過什麼。在此先感謝

+0

是您UIPickerView設置爲包含pickerView班級的UIPickerViewDataSource和UIPickerViewDelegate網點:titleForRow:forComponent :?如果是這樣,看來你也許包含類pickerView:titleForRow:forComponent:被釋放(或者從不爲保留和過期的自動釋放池) –

+0

這是我的接口聲明'@interface PickerView:的UIViewController '。這是作爲另一個ViewController的子視圖加載的。這個ViewController包含pickerView:titleForRow:forComponent:方法。 – Leon

回答

0

看起來你過度釋放你的選擇器視圖,你可以看到這個,因爲消息被髮送到一個autoreleasepool而不是你期望的對象,你應該檢查你的保留/版本爲你的選擇器看看會發生什麼上,不能真正從發佈的代碼告訴...

+0

對不起,我是iPhone新手,我該如何檢查我的保留/發佈? – Leon

+0

發佈代碼創建的代碼 – Daniel

+0

[Interface](http://pastie.org/2613757) [Implementation](http://pastie.org/2613771) – Leon