Take the 2-minute tour ×

I have this code in my table view controller (and delegate):

    DetailStatus *detailViewController = [[DetailStatus alloc] initWithNibName:@"DetailStatus" bundle:nil status:[mStatuses objectAtIndex:indexPath.row]];
    [[self navigationController] pushViewController:detailViewController animated:YES];
    [detailViewController release];     
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
    NSLog(@"exiting didselectrow");


And in my DetailStatus class:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil status:(NSDictionary *)pStatus {
    NSLog(@"I am being called %d", [pStatus objectForKey:@"id"]);
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {
        // some stuff
    return self;

The funny thing is, my DetailStatus is actually being initialised, in the console window, it even outputs "I am being called 000001" but strangely the view is not being pushed to the table view...

I've checked the nib name, and it's ok. I checked the DetailStatus heading file, it looks ok (like this):

@interface DetailStatus : UIViewController {

So does anyone know why the view is not being pushed to the window even if I've initialised it and pushed it?

UPDATE: I tried logging some debugging messages to viewDidLoad in DetailStatus, and it seems like the view is not loaded even though the class was instantiated... I wonder why.

UPDATE2: I have a feeling that this might be my navigation controller organisation that's wrong.. I have this following:

Login page -> customtabbar -> First table view -> DetailStatus
                           -> Second table view -> DetailStatus

I think I'm only maintaining one navigation controller in that hierarchy. I've never created other navigation controllers. I only push view after another.

Thank you everyone for the answers! I will give out the bounty soon, I'll let other people vote first before the bounty expires.

share|improve this question
What happens when you try just a plain UIViewController instead of DetailStatus? –  ACBurk Dec 12 '10 at 3:25
add comment

7 Answers

up vote 9 down vote accepted

After looking at it,the scenario seems to be same like me.What I faced for the first time when doing Tab+Navigation.

I am sure that there is some problem with your Tab+Navigation based application. Although it shows the Tab as well as navigation are not able to navigate the basic flow.And it is very difficult to solve your problem with such less code.

Instead of this, I had an alternate solution for the same:

Once you have a tab bar in a XIB, the easiest way to approach this is to drag a UINavigationController object over from the Library window (looks like a left nav bar button on a gold background) into the Tree View for your tab bar (the text only view, not the GUI). Place it under the tab bar, then drag your existing view controller under the tab bar controller instead of under the tab bar.

When you go to view that tab you should then see a navigation bar on the top of it... if you are loading the navigation controller from another xib, you'll modify the nav bar in the tab bar xib.

else you can below you can follow the best url for the same:



Hope this will surely solve your problem.

share|improve this answer
Thank you very much for this. This is a very clear and good answer. I guess my dilemma is whether I should make the login screen part of the navigation controller or not. What I'm currently doing is showing the login screen and pushing the tab bar controller once the user logged in... I guess I'll have to use something else like modal view controller –  Enrico Susatyo Dec 13 '10 at 11:52
Thanks buddy !!!!Hope now you are clear with everything –  Ajay Sharma Mar 19 '11 at 18:17
add comment

Unless the UINavigationController is the immediate parent of your table view controller, [self navigationController] will return nil.

I'm unclear exactly where it lies in the view controller hierarchy, based on your explanation, but I suspect you might have your UITabBarController nested within the navigation controller, when it should be the other way around. If, by chance, you actually mean to push the tab bar off screen (and thus you do want the tab bar controller nested within the navigation controller), you will need to call something like the following:

UIViewController *parentViewController = self.parentViewController;

P.S. Once the push is working correctly, you won't need to deselect the tapped row, as UITableViewController does this automatically when the view reappears.

share|improve this answer
Thanks for the answer. I was meaning to make something like Twitter for iPhone's UI (wiredbob.com/blog/2009/4/20/…) So that I can manage to show something like a login screen. But now I think it might be a bad idea according to your explanation... I'll think about it more carefully before continuing with the project. –  Enrico Susatyo Dec 12 '10 at 3:18
I think your design is okay. It is perfectly fine to use a tab bar and have a navigation controller in each of its tabs. I'd follow Justin's first suggestion and check if [self navigationController] maybe returns nil. This would best fit the symptoms, as you are allowed to send messages to nil, but nothing happens. –  Björn Marschollek Dec 12 '10 at 9:55
The navigationController does not need to be the immediate parent of the your viewController. Your viewController just needs to be in the navigationControllers list of viewControllers it is managing (i.e., yours was pushed on or whatever) for it to have a navigationController property not be nil. –  chadbag Sep 27 '12 at 19:56
add comment

I not seen putting status on the end of the init of the view. Guessing that's something you added.

Dont you just need to do [self pushViewController etc instead of the navigationController bit

share|improve this answer
No... I need to call it from the navigation controller, because it's a method to UINavigationController. When doing [self pushViewcontroller] I'll end up with unrecognized selector crash –  Enrico Susatyo Dec 10 '10 at 0:04
add comment

Could it be that the nib is not wired up correctly. I.e. In the nib there is no connection between the view and the controller so even though the controller is pushed correctly, the navigation controller cannot find the view.

Just a guess!

share|improve this answer
Well, the thing is that the File Owner has been set to that class, and the view of that File Owner has been set to something... Now I'm thinking it might be my navigation controller hierarchy that's acting up –  Enrico Susatyo Dec 10 '10 at 0:38
add comment

alt text

You need to implement like above In tab controller put navigation controller according to your tabs and in navigation controller you can put your tab item.And also you need to set tab bar item nib file.then on tapping a tab you get tab screen and because of navigation controller you can easily navigate.even you can navigate on the screen of any tab main screen. This is the way which you need to implement.

It definitely helps you but you need some logical implementation.

share|improve this answer
add comment

Is your tableViewController directly pushed to the navigation controller or is there another viewController in between ? Check the value of [self navigationController] against the value of your navigationController (from the place your actually instanciate it)

share|improve this answer
add comment

Once check that have you initialized the First Tableview and Second TableView with Navigation controller or not.

While adding to the tabBar, have you added the UINavigationController or only the UIViewController object.

PM_FirstNavigationController *First_navController = [[PM_FirstNavigationController alloc] initWithRootViewController:FirstTableViewController];

tabBarController.viewControllers= [NSArray arrayWithObject: First_navController];

You have to add the view controllers to the tabBar's like that.

Then while calling the [self navigationController], it will give navigation controller object.



share|improve this answer
add comment

Your Answer


