我在Unity 3d和iOS之间有一个桥梁来传递数据。我可以使用extern" C"成功地将数据从unity 3d发送到我的iOS,然后我可以使用extern" c"的方法调用目标c方法。但是从目标c方法来看,如果我想推送另一个viewcontroller,那么它会崩溃并显示以下问题。
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...
我该如何解决这个问题?
这是我的View Controller类:
@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);
}
}