[英](iOS) How can I get the UIViewController from a C++ Application?
I need to use a library in my C++ project that needs to call an extern function: 我需要在C ++项目中使用需要调用extern函数的库:
SetGameViewController(UIViewController* gameViewController)
I have zero knowledge of Objective C and iOS yet. 我对Objective C和iOS的了解为零。 I need to get UIViewController and pass it to that function.
我需要获取UIViewController并将其传递给该函数。
So this code should get the UIViewController: 因此,此代码应获取UIViewController:
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = window.rootViewController;
I also added this import: 我还添加了此导入:
#if defined(OS_IPHONE)
#import <UIKit/UIKit.h>
#endif
I get compiler errors like: 我收到类似以下的编译器错误:
Expected unqualified-id
Unknown type name 'NSString'
I've started learning Objective C and read a few articles but couldn't get much further than that yet. 我已经开始学习Objective C,并阅读了几篇文章,但是到目前为止还远远没有得到更多。 So basically my question is how do I basically import and use Objective C code in C++ code so that I can get and use the UIViewController?
因此,基本上我的问题是,我如何基本上在C ++代码中导入和使用Objective C代码,以便可以获取和使用UIViewController?
最简单的方法是使用扩展名“ .mm”重命名源文件-然后将其编译为Objective-C ++,这意味着您在充分利用C ++的同时仍可与Objective-C对象进行交互(计数指针)从NSObject“衍生”的东西)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.