Добавим действие для кнопки.
Способ 1 (через IBAction)
- (IBAction)buttonAction:(id)sender { NSLog(@"Button Action"); }
Способ 2 (через код)
#import "DetailViewController.h" @interface DetailViewController () @property (weak, nonatomic) IBOutlet UITextField *textField; @property (weak, nonatomic) IBOutlet UIDatePicker *datePicker; @property (weak, nonatomic) IBOutlet UIButton *buttonSave; @end @implementation DetailViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self.buttonSave addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)save { NSLog(@"save"); } @end
UIControlEventTouchUpInside означает, что метод сработает, когда пользователь нажмет на кнопку и отпустит её.