简体   繁体   English

(iOS)如何从C ++应用程序获取UIViewController?

[英](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.

相关问题 如何从另一个C ++控制台应用程序启动/结束C ++控制台应用程序? - How can I start/end a C++ Console Application from another C++ Console Application? 我如何从 qt 应用程序 (c++) 打开可执行文件 - How can i open an executable from an qt application (c++) 我可以在 iOS 或 mac 应用程序中使用 C++ 代码吗? - Can I use C++ Code in iOS or mac application? 如何摆脱C ++中的强制转换? - How can I get away from casting in C++? 如何从 C++ object 获取 class 名称? - How can I get the class name from a C++ object? 如何在C ++中从字符串指针获取字符? - How can I get a character from a string pointer in C++? 在c ++中,我如何从一个对象到一个静态成员? - In c++, how can I get from an object to a static member? 如何在WinRT中从C ++获取堆栈跟踪? - How can I get a stacktrace from C++ in WinRT? 如何将对象(或指针)从C ++ .NET应用程序发送到VB应用程序 - How can I send an object (or pointer) from C++ .NET application to VB application 如何从Windows Service主要功能启动C ++本机应用程序(该应用程序与控制台交互)? - How can I launch a C++ native application from a Windows Service main function (the application interacts with the console)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM