Accessing the UITabBar Controller

Discussion in 'iOS Programming' started by fergusjk, Sep 15, 2010.

  1. fergusjk macrumors member

    Joined:
    Aug 23, 2010
    Location:
    Ayrshire Coast, Scotland
    #1
    I'm creating a tabbar app that has 4 views (and rising).

    I want to be able to click a UIButton on view 1 and the app shall go to view 3 in the exact same way as though the user had touched the the third tab whilst in view 1.

    Please don't respond with the obvious "why wouldn't the user just touch tab 3" as I'm a noob and trying to implement this as a way of understanding how much control I can exercise over the tab bar controller.

    There must be an easy way to get a handle on the tabbar controller, then call a method or do something with that handle so that the app moves along to different views (tabs)?

    Thanks in Advance.
     
  2. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    tabBarController.selectedIndex = 0;
    tabBarController.selectedIndex = 1;
    tabBarController.selectedIndex = 2;
    tabBarController.selectedIndex = etc;
     
  3. fergusjk thread starter macrumors member

    Joined:
    Aug 23, 2010
    Location:
    Ayrshire Coast, Scotland
    #3
    Perfect!!!

    I didn't even realise a handle for the tab bar controller was created in the appDelegate.

    So, to be clear, I just added this method to the appDelegate
    -(void) changeView{
    tabBarController.selectedIndex = 2;
    }

    And called that from my first view and it changed straight away.

    Thanks ulbador.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Probably don't even need to put the method in appDelegate; you can keep it in your view1 controller. Then do something like:
    Code:
    -(void) changeView{
        ProjectNameAppDelegate *appDelegate = (ProjectNameAppDelegate *)[[UIApplication sharedApplication] delegate];
        appDelegate.tabBarController.selectedIndex = 2;
    }
     

Share This Page