为什么我的UILabel没有更新dateselect器更改?

#import "DatePickerViewController.h" #import <Parse/Parse.h> @interface DatePickerViewController () @end @implementation DatePickerViewController @synthesize dateLabel; @synthesize pick; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIBarButtonItem *saveDate = [[UIBarButtonItem alloc] initWithTitle:@"Save Date" style:UIBarButtonItemStyleDone target:self action:@selector(saveList:)]; self.navigationItem.rightBarButtonItem = saveDate; pick = [[UIDatePicker alloc] init]; [pick setFrame:CGRectMake(0,200,320,120)]; [pick addTarget:self action:@selector(updateDateLabel:) forControlEvents:UIControlEventValueChanged]; } -(void)saveList:(id)sender { // need to finish } -(IBAction)updateDateLabel { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateStyle:NSDateFormatterLongStyle]; [formatter setTimeStyle:NSDateFormatterMediumStyle]; dateLabel.text = [NSString stringWithFormat:@"%@", [formatter stringFromDate:pick.date]]; } 

你从-updateDateLabel:(id)arg注册事件是使用一个需要一个参数的select器( @selector(updateDateLabel:)需要form -updateDateLabel:(id)arg )的方法,而你实现的没有参数( -updateDateLabel

当然,考虑到您已经从故事板中的已归档的select器中重新分配了select器,所有这些都是没有意义的。 删除初始化代码,并将IBAction连接到故事板中的select器。

更改-(IBAction)updateDateLabel { to -(IBAction)updateDateLabel:(id)sender {