我得到我的实现网页,我已经注释掉上未完全执行警告:未完全执行
#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属性。您可以通过设置断点并查看它是否为有效对象来进行双重检查。 –