I am new in xcode. I have created a dialog and ok button on the dialog. Now, I am doing some operation on dialog. After that I want to click on ok button to close the dialog box. for this I am doing like
in .h file
@interface viewcontroller:NSViewController
@property (weak) IBOutlet NSButton *OkBtn;
@end
in .m file
"I don't know how to write the code for ok button in .m file. I just want to when click on OK button , just close the dialog.
Instead of create IBOutlet, you have to make IBAction
to directly get click event
check out this image...
This Is .m
file where i create IBAction
directly
and if you want to give click event programatically then follow @Nicolas Buquet answer
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 okButtonTapped:
method will be called when you tap iside the button and remove your finger (the 'up" part).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With