我有一个 UIbutton 调用同一个类中的方法,我正在使用 @selector 并传递了方法名称,我设置了一个断点并注意到该方法根本没有到达,我编写了这段代码,我认为它工作正常,但它永远不会到达方法体:
- (IBAction)setEndTime:(id)sender {
[self performSegueWithIdentifier:@"showEndTimePicker" sender:sender];
UIViewController *TimePickerVC=[self.storyboard instantiateViewControllerWithIdentifier:@"setEndTime"];
packtimePicker=(UIDatePicker*)[TimePickerVC.view viewWithTag:2];
NSLog(@"PickerTag%i",packtimePicker.tag);
self.finishedTime=packtimePicker.date;
// NSLog(@"Date returned is ---> %@",finishedTime);
UIButton *btn=(UIButton*)[TimePickerVC.view viewWithTag:3];
NSLog(@"Button Tag%i",btn.tag);
[btn addTarget:self action:@selector(setSelectedValueToAttr:) forControlEvents:UIControlEventTouchUpInside];
方法:
-(void)setSelectedValueToAttr:(UIButton *) sender{
finishedTime=packtimePicker.date;
NSLog(@"Time returned----> %@",finishedTime);}
}