How to write ok button action in Objective-c?
I am new to xcode... I created a dialog and an ok button in the dialog. Now I am doing the dialogue operation. After that, I want to click ok button to close the dialog. for this i do as
in .h file
@interface viewcontroller:NSViewController
@property (weak) IBOutlet NSButton *OkBtn;
@end
in the .m file
"I don't know how to write the code for the ok button in the .m file. I just want to click OK, just close the dialog.
+3
source to share
3 answers
Add this to your code:
[OkBtn addTarget:self action:@selector(okButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
and add this method to your class:
- (void)okButtonTapped:(UIButton *)sender {
NSLog(@"Ok button was tapped: dismiss the view controller.");
}
The method okButtonTapped:
will be called when you press the button and remove your finger (the "up" part).
+1
source to share