gpt4 book ai didi

objective-c - 跨类访问 NSApplicationDelegate 方法

转载 作者:行者123 更新时间:2023-12-03 17:31:28 24 4
gpt4 key购买 nike

ApplicationDelegate.h中,我有:

@interface appDelegate : NSObject <NSApplicationDelegate>

- (IBAction)showPage:(id)sender;

buttonController 中(连接到 Xib 中按钮的发送操作)我有另一个函数

- (IBAction) clickAction:(id)sender {
NSLog(@"Clicked");
}

我想使用类似以下内容的按钮触发该功能:

- (IBAction) clickAction:(id)sender {
[showPage:nil];
NSLog(@"Clicked and the page is shown");
}

跨类访问 showPage 函数的正确方法是什么?

最佳答案

从当前应用程序获取委托(delegate),然后调用它的方法。

[(appDelegate*)(NSApplication.sharedApplication.delegate) showPage:nil];

关于objective-c - 跨类访问 NSApplicationDelegate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24856714/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com