2011-11-30 66 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文件