2011-11-30 82 views
4

我得到我的實現網頁,我已經註釋掉上未完全執行警告:未完全執行

#import "BIDDatePickerViewController.h" 

@implementation BIDDatePickerViewController // Incomplete implementation 

@synthesize datePicker; 

- (IBAction)buttonPressed:(id)sender 
{ 
    NSDate *selected = [datePicker date]; 
    NSString *message = [[NSString alloc] initWithFormat:@"The date and time you selected is:%@", selected]; 
    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:@"Date and Time Selected" 
          message:message 
          delegate:nil 
          cancelButtonTitle:@"Yes I did" 
          otherButtonTitles:nil]; 
    [alert show]; 
} 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    NSDate *now = [NSDate date]; 
    [datePicker setDate:now animated:NO]; 
} 

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

} 
@end 

而且消息的定製部件,顯示日期,選定的時間顯示不正確的。爲什麼?

以下是接口文件:

#import <UIKit/UIKit.h> 

@interface BIDDatePickerViewController : UIViewController 

@property (strong, nonatomic) IBOutlet UIDatePicker *datePicker; 

-(IBAction)buttonPressed; 

@end 

回答

13

你得到一個警告的原因是因爲你實現的方法- (IBAction)buttonPressed:(id)sender,當你定義的方法-(IBAction)buttonPressed;。請注意接口上缺少參數。

+0

謝謝你,工作。無法弄清楚爲什麼選擇的NSDate *沒有傳遞給UIAlertView消息。信息的其餘部分正在出現,但涉及*選定。它在消息中顯示爲(null)。任何想法爲什麼? – pdenlinger

+0

最有可能是因爲你忘了在界面構建器中連接你的datePicker屬性。您可以通過設置斷點並查看它是否爲有效對象來進行雙重檢查。 –

0

在您的.h文件中必須- (IBAction)buttonPressed;和你.m文件你有- (IBAction)buttonPressed:(id)sender。你應該有- (IBAction)buttonPressed;在.m文件