lp6m
lp6m

Reputation: 65

How to call UIViewController from cocos2d-x?

How to call UIViewController from cocos2d-x?

I develop my app in cocos2d-x(C++). For iOS & Android, I have to write native code.(Objective-c,java).

I want to call UIViewController.The following code crash.

void NativeLauncher::CallMyViewController(){
    UIViewController *myViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
    QRViewController *newViewController = [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:nil];
    [myViewController presentViewController: newViewController animated:YES completion: nil];//crash
}


Anyone know how to do?

Upvotes: 0

Views: 1240

Answers (1)

Bhavuk Sehgal
Bhavuk Sehgal

Reputation: 121

Just use this code in your .mm class,this is the way to call any viewController from cocos2d-x

ViewController *newViewController = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
AppController *appController = (AppController *)[[UIApplication sharedApplication] delegate];
    [appController.viewController presentViewController:newViewController animated:YES completion:Nil];

Upvotes: 1

Related Questions