Search code examples
objective-ccocoansviewcontroller

How to perform IBAction before dismiss sheetViewController from same UIButton?


I am writing a Cocoa Mac app in Objective-C and using Storyboard for my UI.

I have a "Confirm" button in my sheetViewController.m which I want to perform some action (save some settings) as well as dismiss the sheetViewController at the same time. They both use the sheetViewController.m as outlets.

Unfortunately, with Storyboard, I can only pick one received action (IBAction) or dismissController.

I want to perform the IBAction FIRST, before dismissing the sheet. How can I accomplish this?

Happy to do this in code as well instead of Storyboard if necessary!

Thanks!


Solution

  • I found out how to reference Storyboard ID in code:

    On MainViewController:

    - (IBAction)didClickButton:(NSButton *)sender {
        SheetViewController *sheetViewController = [self.storyboard instantiateControllerWithIdentifier:@"SheetViewController"];
        // Must match Storyboard ID
        [self presentViewControllerAsSheet:sheetViewController];
    }
    

    On SheetViewController:

    - (IBAction)didClickButton:(NSButton *)button {
        // Do something
        [self dismissViewController:self];
    }