1
votes

Currently in my project, I made a custom tab bar controller to achieve vertical tab bar effect just like the standard tab bar controller. In the custom tab bar, I have two buttons linked with custom segue to two view controllers. What this custom segue does is to replace the subview inside my custom tab bar controller with the two view controllers.

After I've done this, my custom tab bar controller works fine when switching between the two buttons. However, when I try to place a button onto one of the view controllers and add a modal segue from the button to a brand new view controller, problem happens. When I pressed the button, the program crashes.

I'm thinking the problem might be the view controller hierarchy problem. On the other hand, I created a new project with same storyboard structure and custom segue, this time, when I place a button in one of the view controller and connects using a modal segue to a new view controller, it works, but with a warning saying "Presenting view controllers on detached view controllers is discouraged".

I'm very confused right now. Could someone point me to the right direction?

Thanks in advance!

1

1 Answers

0
votes

Maybe this won't help that much, but this is one way to do it if you were doing this programmatically, which you may be able to interpret this answer to Storyboards:

-(void)dismiss
{
    [[self navigationController] dismissViewControllerAnimated:true completion:nil];
}

-(void)showModal
{
    NewCustomViewController * pvc = [NewCustomViewController new];
    CustomNavigationController * ffs = [[CustomNavigationController alloc] initWithRootViewController:pvc];
    [ffs setNavigationBarHidden:TRUE];
    UIBarButtonItem * backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"exit-button"] style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
    [[pvc navigationItem] setLeftBarButtonItem:backBarButtonItem];
    [[self navigationController] presentViewController:ffs animated:true completion:nil];
}

I've created my own UITabBarController in the past and successfully used this same method for modal presentation from the custom UITabBarController subclass, try it out, I know it's not storyboards, but it's similar. In fact, let me change something to make this easier for you.

Also, do you have your viewcontrollers nested inside navigationControllers in the custaom tabbar?

should be like this

UItabbarcontroller
   navigationcontroller
       viewcontroller
   navigationcontroller
       viewcontroller

this works the easiest, also, could be even better like this:

navigationController <== mainscreen rootViewController as a navigationController in the AppDelegate
   UItabbarcontroller
      navigationcontroller
          viewcontroller
      navigationcontroller
          viewcontroller

Now, you say the tabbar isn't nested inside a navigationcontroller right? so we are talking about this:

should be like this

UItabbarcontroller
   navigationcontroller
       viewcontroller
   navigationcontroller
       viewcontroller

The problem with this is the fact that if I call a modal from the UItabbarcontroller subclass and do a :

    self.navigationController present XXX etc. etc, 

then this is going to fail, more than likely since the tabbarcontroler doesnt have a navigationController

Also if you call segue navigation with a navigation controller from one of the veiwcontrollrs and you try to self.navigationctonroller present, then you have the same issue, there's no navigaitoncontroller.

You an try to present modal from

  [self present ... blah blah

but doing this wont allow user interaction from the presented modal since it wasn't presented in a navigation controller, I would smash your TabbarViewcontroller into a navigationcontroller, it shouldn't be that hard and then I'd root your viewcontrollers in your tabbar in a Navigationcontroller first and then try out those buttons again, that's just three additional navigationcontrollers, no big deal