I have a bridge between unity 3d and iOS to pass data. I can sent data successfully from unity 3d to my iOS using extern "C", then i can call a objective c method from a method of extern "c". But from the objective c method, if i want to push another viewcontroller then it crashes and show the following issue.
A view can only be associated with at most one view controller at a time! View is associated with Clear this association before associating this view with...
How can i solve this issue ?
Here is my View Controller class :
@implementation ARViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Just setting Unity delegates and view to add it as subview for my main view.
// This allow me to add a UIButton above the UnityView to popViewController or anything i want to make native in iOS.
unityViewController = [[UnityDefaultViewController alloc] init];
unityController = (UnityAppController*)[[UIApplication sharedApplication] delegate];
unityViewController.view = (UIView*)unityController.unityView;
[viewToUnity addSubview:unityViewController.view];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)gotoAnotherViewController
{
ViewController *arVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"ClickVC"];
[self presentViewController:arVC animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
});
}
@end
extern "C" {
void _NativeMethodName(const char* stringValue)
{
[[ARViewController new] gotoAnotherViewController];
NSLog(@"Passed string value: %s", stringValue);
}
}