Replacing a tab view with a new view

Discussion in 'iOS Programming' started by Cindori, May 8, 2011.

  1. macrumors 68040

    Cindori

    Joined:
    Jan 17, 2008
    Location:
    Sweden
    #1
    I have a tab view set up and working fine, with individual controllers for the views.

    However, in one of the views, I want a button that is going to load a new view.

    But! This view should not just replace the view of the tab. It should replace everything in the window, making the tab bar itself disappear.

    I believe this is supposed to be achieved by UINavigationController in some way.

    I started learning iPhone developing yesterday, so noobdetails are appreciated.


    An illustration of what I want to achieve:

    [​IMG]
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You could use a UINavigationController. If you do that it has to be the root view controller. Or you could present the new view controller modally. The documentation will give you details on either.
     
  3. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #3
    Like ROBBIEDUNCAN said.
    In the mainwindow u have couple of "View Controllers", inside the Tab Bar Controller, drag a Navigation Controller from ur library, insert it, and use that.
    U can use [self.navigationController pushViewController:pointerToUIViewController animated:YES];

    Then it should do EXACTLY like u want ;p
    Or do a modal transition style, if it's just for displayin info or w/e

    SO many options ;p
     
  4. Cindori, May 9, 2011
    Last edited: May 9, 2011

    thread starter macrumors 68040

    Cindori

    Joined:
    Jan 17, 2008
    Location:
    Sweden
    #4
    So now I have

    My MainWindow and AppDelegate
    This contains the navigation controller

    [​IMG]


    ScheduleView - this is supposed to be view 2 of my navigation, and is illustrated in the original post right image (the "a new view")

    [​IMG]


    TabViewController - this is supposed to be view 2 of my navigation, and is illustrated in the original post left image

    [​IMG]




    And now I want that "Tillbaka" (Backwards) - button in ScheduleView to load the TabViewController view...

    So in ScheduleViewController.m I have this code:

    [​IMG]


    As you can see in the first image, I load my main window view from "ScheduleView"

    But when I press the Tillbaka-button, I get:

    Application tried to push a nil view controller on target <UINavigationController: 0x4b15a30>.


    What am I missing?

    EDIT:

    aha, so I changed the button action a little bit:


    [​IMG]

    and now I get a view atleast, although it's all white

    gonna see if Im missing something in TabViewController





    Edit 2

    Still having problems, I don't get why my view and tab controller are separate from each other?

    [​IMG]
     
  5. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #5
    Not completely sure if u made it switch to the second view like Robbie/me suggested.
    If that worked, and u just want a back button u can do it like this
    Code:
     - (IBAction) goBack:(id) sender {
     [self.navigationController popViewControllerAnimated:YES];
    }
    have fun.
     
  6. thread starter macrumors 68040

    Cindori

    Joined:
    Jan 17, 2008
    Location:
    Sweden
    #6
    I figured it out.


    What I did wrong was trying to have a NavigationView encapsule a TabView, because I wanted to get rid of the TabBar when I switched NavigationView.

    However the correct way was to have a TabView encapsule a NavigationView, and then on switching to a new NavigationView, to set

    self.hidesBottomBarWhenPushed = YES;


    and then set it to NO when I switched back.

    tutorial:
    http://broadcast.oreilly.com/2009/06/tab-bars-and-navigation-bars-t.html
     

Share This Page