Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aidanlee

macrumors newbie
Original poster
May 4, 2009
2
0
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
 
pushviewcontroller with tabbarcontroller

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

Hi Aidan,

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

Regards,

Yoga.
 
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.
 
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!
 

Attachments

  • Picture 1.png
    Picture 1.png
    98.9 KB · Views: 1,131
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.
 
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.
 
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!
 
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

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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.