PDA

View Full Version : pushViewController with TabBarController




aidanlee
May 4, 2009, 04:01 PM
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
- (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



Yogachitra
Jul 9, 2009, 04:24 AM
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
- (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

Hi Aidan,

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

Regards,

Yoga.

mraheel
Jul 10, 2009, 07:55 PM
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.

aidanlee
Jul 16, 2009, 09:01 PM
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!

computerartist
Oct 9, 2010, 10:13 AM
I am having the same problem.

hiddepolen
Apr 25, 2011, 04:27 AM
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.

Sykte
Apr 25, 2011, 07:01 AM
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.

Posting code and telling us what type of debugging you have already tried would be great.

hiddepolen
Apr 25, 2011, 08:03 AM
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!

wimc
May 26, 2011, 01:32 AM
Woah! 2 years later and you still rock :p Srsly, thanks a lot I had been breaking my head over this for days now

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!