How to perform IBAction before dismiss sheetViewController from same UIButton?

最后都变了- 提交于 2019-12-25 06:45:28

问题


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!


回答1:


You can use codes to dismiss controller in your IBAction.




回答2:


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];
}


来源:https://stackoverflow.com/questions/38886877/how-to-perform-ibaction-before-dismiss-sheetviewcontroller-from-same-uibutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!