我得到我的實現網頁,我已經註釋掉上未完全執行警告:未完全執行
#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
謝謝你,工作。無法弄清楚爲什麼選擇的NSDate *沒有傳遞給UIAlertView消息。信息的其餘部分正在出現,但涉及*選定。它在消息中顯示爲(null)。任何想法爲什麼? – pdenlinger
最有可能是因爲你忘了在界面構建器中連接你的datePicker屬性。您可以通過設置斷點並查看它是否爲有效對象來進行雙重檢查。 –