0

Issue:

An UITabBarController delegate method calls viewDidLoad and negates/ignores the screen selection.

Background:

I am making a split-view controller for small iOS screens. So, far the screen looks something like this:

Custom Split-View Controller

For the Detail View (RS), I'm using a UITabBarController, with the TabBar removed. You can find the code for this here.

The user selects the buttons on left, and a delegate sends the button's tag id to the UITabBarController delegate method.

The delegate method looks like this:

// delegate method in subclass of UITabBarController
-(void) screenSelected:(int)screenNum
{
    NSLog(@"delegate arrived: %d", screenNum);
    self.selectedIndex = screenNum;
    // code goes to viewDidLoad
}

With breakpoints in place, I determined that the screen does not actually change.

If this screenSelected method is instead called from the UITabBarController viewDidLoad method (when the app first opens), the method works fine and the selectedIndex is changed as expected.

I'm trying to figure out why the delegate is triggering viewDidLoad. Does the delegate reset the view?

Thanks

Community
  • 1
  • 1
Dev
  • 13
  • 4
  • What you exactly want ? can't understand question properly? – Ketan Parmar Apr 20 '16 at 05:32
  • I would like for the delegate method to display the proper viewController, and not have the viewDidLoad method called each time the delegate message is received. viewDidLoad resets the selectedIndex to 0. – Dev Apr 20 '16 at 07:15

1 Answers1

0

Yes, viewdidload will call every time because you are initializing tabs again. setSelectedIndex intialize tabbarcontroller evrytime from UITabbarcontroller class. You should not do that from uitabbarcontroller class. just initialize tabbarcontroller onece.

You should not use tabbarcontroller like this way. according to your requirement you not need to use tabbar just shows viewController on button click.

hope this will work.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • The solution is to place the viewControllers in a containerView and then swap the views with segues from the buttons. The goal is to organize the views and the tabBarController seemed like a possibility.Thanks for your help. – Dev Apr 21 '16 at 11:55