2011-09-30 86 views
0

我正在創建一個textField,點擊後UIPickerView出現。 當我運行此代碼時出現錯誤: Thread 1:Profram received signal:"SIGABRT"Popup UIPickerView(iphone)

我對iPhone的開發很新,但負責人不在,我正在接受一個項目。

如果你可以讓我知道什麼是不對的......

這是ViewController.h的樣子:

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController { 

IBOutlet UIPickerView *picker; 
IBOutlet UITextField *text; 

} 


- (IBAction)showPicker:(id)sender; 


@end 

ViewController.m

#import "ViewController.h" 
@implementation ViewController 
- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 
} 


- (void)viewDidDisappear:(BOOL)animated 
{ 
[super viewDidDisappear:animated]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
// Return YES for supported orientations 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); 
} else { 
    return YES; 


} 
} 

- (void)showPicker { 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.4]; 
[UIView setAnimationDelegate:self]; 
picker.center = CGPointMake(160, 240); 
[UIView commitAnimations]; 


if (!self.navigationItem.rightBarButtonItem) { 
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]  initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)]; 
    [self.navigationItem setRightBarButtonItem:doneButton animated:YES]; 
    // [doneButton release]; 
} 
} 


- (void)hidePicker { 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.4]; 
[UIView setAnimationDelegate:self]; 
picker.center = CGPointMake(160, 240); 
[UIView commitAnimations]; 


[self.navigationItem setRightBarButtonItem:nil animated:YES]; 
} 


- (void)done:(id)sender { 

[self hidePicker]; 

[self.navigationItem setRightBarButtonItem:nil animated:YES]; 
} 


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 

[self showPicker]; 

return NO; 
} 

回答

0
- (IBAction)showPicker:(id)sender; 

這函數沒有在你的.m文件中實現,而不是 - (void)showPicker使用上面的那個...

,什麼是使用這個......

- (void)done:(id)sender 
0

選擇器視圖必須有一個數據源獲取數據,以顯示和委託對事件作出迴應。通常我會通過採用相應的協議UIPickerViewDelegate和UIPickerViewDataSource來定義控制器。你的控制器沒有,這可能意味着數據源和委託在另一個對象內。你應該檢查界面生成器,緊緊點擊選擇器,看看他的代表和數據源。如果你發現另一個類比你的控制器,那麼你應該尋找錯誤。如果你發現你的控制器的類,那麼問題是你沒有實現用於填充選擇器視圖的方法。作爲參考,拾取器至少在尋找數據源方法:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view 

爲狩獵運氣好。