EricHolsinger.com

Icon

This is where you get the spin on Eric Holsinger.

Show the UINavigationController Root View Controller in UITabBarController

When programming on iPhone or iPad, it’s common to have a UITabBarController mixed with UINavigationController.

You will probably find yourself needing to show the Root View Controller of a Navigation Controller when you switch Tabs in the Tab Controller. In your UITabBarControllerDelegate you implement the following method.


- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController;

Showing the Root View Controller is as easy as calling popToRootViewControllerAnimated. You’ll want to check the viewController parameter to see if it is a kind of UINavigationController. If it is, cast it and then call popToRootViewControllerAnimated.


- (void) tabBarController: (UITabBarController *) tabBarController
                                        didSelectViewController: (UIViewController *) viewController {
	if ([viewController isKindOfClass:[UINavigationController class]]) {
		[(UINavigationController*)viewController popToRootViewControllerAnimated:NO];
	}
}

In this way, you won’t get warnings like the following.

'UIViewController' may not respond to '-popToRootViewControllerAnimated:' ...

That is what happens when you make the call on a UIViewController like this.


[viewController popToRootViewControllerAnimated:YES];

By using isKindOfClass to identify the kind of UIViewController, you will also be able to mix your View Controllers in your Tab Controller. The check for Class membership will ensure that your are only invoking the method on the right kinds of objects.

You can read more about Introspection in the Apple
Cocoa Fundamentals Guide.

If you enjoyed this post, make sure you subscribe to my RSS feed!

 

 

Disclosure: All of the products and services discussed on this site were purchased by myself, unless otherwise noted. Affiliate links are sometimes included in the posts. I generally don't get freebies to review or get paid to review things (outside of affiliate links). If I get it for free, I'll tell you. Material compensation does not influence my opinion and my views are my own.

 

Category: Programming

Tagged:

Viewed:3,974

Leave a Reply

Contact Information

Eric Holsinger
Saco, ME 04072
ph: 207 . 749 . 1703
eM: eric.holsinger@gmail.com
My company: Whirlidoo, LLC

View Eric Holsinger's profile on LinkedIn

Categories

My Twitter noise...

  • Sencha Touch had been slick, but oddball things, like setting scrollable to false on a form panel to render it, cause me stress. 18 hrs ago
  • Google Drive? 2 days ago
  • Am I the only one who thinks coffee from a French press tastes like coffee with little tiny coffee grounds all over my tongue? 3 days ago
  • More updates...

Posting tweet...

Powered by Twitter Tools


Banner