Search code examples
iphoneiosuiviewcontrolleruinavigationcontrolleruitabbar

Multiple ViewControllers onscreen


I would like to place two UIViewControllers on a window (like you can see below). Is it possible to set this up to each view is controlled by it's own controller respectively? enter image description here

In the app delegate I'm adding the subview the following way

TabBarViewController *tabBarVC = [[TabBarViewController alloc] init];
CGRect frame = tabBarVC.view.frame;
frame.origin.y = self.window.bounds.size.height - frame.size.height;
tabBarVC.view.frame = frame;
[self.window insertSubview:tabBarVC.view aboveSubview:tabVC.view];

It loads, but when I click on a button (IBAction), or do anything which needs the controller, the app crashes. What am I doing wrong?

Thanks!


Solution

  • Create a strong reference for an iVar or property for tabBarVC and change this line:

    TabBarViewController *tabBarVC = [[TabBarViewController alloc] init];
    

    To:

    tabBarVC = [[TabBarViewController alloc] init];
    

    Or

    self.tabBarVC = [[TabBarViewController alloc] init];