0

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);
    }

}
Nuibb
  • 1,800
  • 2
  • 22
  • 36
  • You are not allowed to have a controller inside another controller. – KKRocks Apr 19 '17 at 09:57
  • Then how can i fix this issue ? – Nuibb Apr 19 '17 at 10:11
  • is it crash on viewdidload ? – KKRocks Apr 19 '17 at 10:14
  • No, It crashes in gotoAnotherViewController method where i'm trying to push another view controller – Nuibb Apr 19 '17 at 10:14
  • I think it's the problem with unity 3d view controller from where Extern c block is called. That view controller is alive and I'm trying to push a viewcontroller from ios that is violating the OS rule. Is there any way to push a viewcontroller from iOS after switching from unity3d to iOS ? – Nuibb Apr 19 '17 at 10:40
  • Can you paste here the full stacktrace? And why are you doing this: `"unityViewController.view = (UIView*)unityController.unityView" ?` I think this is the actual line which causes the problem. You have ONE View (which you take from (unityController) and you are trying to associate it with the another viewController (unityViewController). The view can only be assigned to one view controller. – maros Apr 19 '17 at 12:52
  • I have solved the crashes. Thanks for support...:) – Nuibb Apr 20 '17 at 06:11

0 Answers0