Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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: Call a function from another Class - Obj C

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

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

Refer to the Key-Value Coding Programming Guide

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top