问题描述
我正在用Objective-C编写一个Cocoa Mac应用,并将Storyboard用于我的UI。
I am writing a Cocoa Mac app in Objective-C and using Storyboard for my UI.
我的sheetViewController.m中有一个确认按钮,我想要执行一些操作(保存一些设置)以及同时关闭sheetViewController。
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.
不幸的是,使用Storyboard,我只能选择一个接收到的动作(IBAction)或dismissController。
Unfortunately, with Storyboard, I can only pick one received action (IBAction) or dismissController.
我想先执行IBAction,然后解散工作表。我该怎么办呢?
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!
谢谢!
推荐答案
我发现了如何在代码中引用Storyboard ID:
I found out how to reference Storyboard ID in code:
在MainViewController上:
On MainViewController:
- (IBAction)didClickButton:(NSButton *)sender {
SheetViewController *sheetViewController = [self.storyboard instantiateControllerWithIdentifier:@"SheetViewController"];
// Must match Storyboard ID
[self presentViewControllerAsSheet:sheetViewController];
}
在SheetViewController上:
On SheetViewController:
- (IBAction)didClickButton:(NSButton *)button {
// Do something
[self dismissViewController:self];
}
这篇关于从同一个UIButton关闭sheetViewController之前如何执行IBAction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!