简体   繁体   English

如何从 UIViewController 调用 AppDelegate 方法

[英]How to call an AppDelegate method from a UIViewController

In my appDelegate.m file I have this method在我的appDelegate.m文件中,我有这个方法

- (void) goToRN {
   [RCTKeyWindow().rootViewController dismissViewControllerAnimated:true completion:nil];
}

and I would like to call this method from my ConsentViewController.swift file like: AppDelegate().goToRN()我想从我的ConsentViewController.swift文件中调用此方法,例如: AppDelegate().goToRN()

but I'm getting this error: Value of type 'AppDelegate' has no member 'goToRN'但我收到此错误: Value of type 'AppDelegate' has no member 'goToRN'

You can get it from the application global variable:您可以从应用程序全局变量中获取它:

NSApp.delegate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM