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