1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

pushViewController with TabBarController

Discussion in 'iPhone/iPad Programming' started by aidanlee, May 4, 2009.

  1. macrumors newbie

    #1
    Hi all,

    I've been successful with using and understanding the use of pushViewController, however, I cannot seem to get it working when I have a TabBar and a NavigationBar on the same view. What I'm trying to do is when a user selects an item in the UITableView (which contains both TabBar and NavigationBar) I want it to go into a details view which would contain a Back button. But when I call on pushViewController with the view nothing happens (the object is loaded but visually nothing is there).

    Example:
    // the table's selection has changed, switch to that item's UIViewController
    Code:
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {	
    	DealsDetailViewController *controller =  [[DealsDetailViewController alloc] initWithNibName:@"DealsDetailView" bundle:[NSBundle mainBundle]];
    	[self.tabBarController.navigationController pushViewController:controller animated:YES];
    	[controller release];
    }
    
    Thanks for your help!

    Cheers,

    Aidan
     
  2. macrumors newbie

    #2
    pushviewcontroller with tabbarcontroller

    Hi Aidan,

    I'm facing the same problem now. Could you please tell me how you solved it?

    Regards,

    Yoga.
     
  3. macrumors regular

    #3
    Navigation bar isnt a sub function of Tab Bar controller..
    AND, i think only the Controller can be pushed. I'm not sure if it wil work for NavigationBAR.
    it should be
    [self.navigationController pushViewController:controller animated:YES];

    You probably decalred UINavigationController in the header file of the ViewController NOT the TabBarController which is the appdelegate.
     
  4. macrumors newbie

    #4
    pushing successfully :)

    Hi Yoga,

    The problem actually spawned from my xib files and actually the solution is quite simple. In my main window where I created a UITabViewController through Interface Builder, I had to create/drag a UINavigationController under the Tab Bar Controller for each tab I had. So the new hiearchy is as follows: Tab Bar Controller -> UINavigationController -> View Controller. So if you have 4 tabs for example, you'll have 4 of the above for each tab. And each move each view controller into its respective navigation controller. From there on you just need to associate and link things as you normally would.

    Hope that helps.

    I attached a picture as a sample. Pictures always helps me...hope it helps you!
     

    Attached Files:

  5. macrumors newbie

    #5
    I am having the same problem.
     
  6. macrumors newbie

    #6
    Hi,

    I actually have exactly the same problem described in this thread. I have my Tab and Nav controllers with the Views exactly as you have them in the picture. I the code to push the new View in my app delegate, and connected to a Navigation bar button.
    Everything builds without a single error, but when I click the button, nothing happens.

    Any idea's what I did wrong?

    Thanks in advance.
     
  7. macrumors regular

    #7
    Posting code and telling us what type of debugging you have already tried would be great.
     
  8. macrumors newbie

    #8
    Thanks, I have solved it. The problem was that I didn't use the correct navigation controller. I used an object which I made earlier, instead of the NavController which should have been used.

    Thanks anyway for your reply!
     
  9. macrumors newbie

    #9
    still rockin'

    Woah! 2 years later and you still rock :p Srsly, thanks a lot I had been breaking my head over this for days now

     

Share This Page