views:

63

answers:

3

I have a RootViewController that has some UITabBarController properties:

@interface RootViewController : UIViewController<LoginViewDelegate, UITabBarControllerDelegate> {
    UIBarButtonItem*    loginButton;
    NSUserDefaults*     prefs;
    UITabBarController* arTabBarController;
    UITabBarController* stvTabBarController;
    UITabBarController* stTabBarController;
    BOOL                tabBarSaved;
}

@property(nonatomic,retain) UIBarButtonItem*    loginButton;
@property(nonatomic,retain) UITabBarController* arTabBarController;
@property(nonatomic,retain) UITabBarController* stvTabBarController;
@property(nonatomic,retain) UITabBarController* stTabBarController;
@property(assign)           BOOL                tabBarSaved;

I would like to be able to access these tabbarcontrollers from another class.

How can I use UIApplication in another class to access the UITabBarControllers and switch tabs?

A: 

Try implementing a protocol in the root controller and confirm to that protocol in your class. Another way is to use notifications.

Hope that helps.

Also check this post: http://stackoverflow.com/questions/3066651/call-a-function-from-another-class-obj-c

Bucko
A: 

If you use @synthesize in your implementation, then what you're implementing there are public sets of getters and setters.

Which means, if you can get a pointer to your RootViewController here, you can also do anything you want to its .arTabBarController property.

Dan Ray
A: 

You can use "keyPaths" as well. Something like:

UITabBarController *controller = [[UIApplication sharedApplication] valueForKeyPath:@"delegate.rootViewController.arTabController"];

Refer to the Key-Value Coding Programming Guide

falconcreek