如何访问其他类中的属性/方法
我有一个 RootViewController ,它有一些 UITabBarController 属性:
@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;
我希望能够从另一个类访问这些 tabbarcontrollers 。
如何在另一个类中使用 UIApplication 来访问 UITabBarControllers 并切换选项卡?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在实现中使用
@synthesize
,那么您正在实现的就是公共的 getter 和 setter 集。这意味着,如果您可以在此处获取指向 RootViewController 的指针,您也可以对其
.arTabBarController
属性执行任何您想要的操作。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.您也可以使用“keyPaths”。
类似于:
请参阅 键值编码编程指南
You can use "keyPaths" as well.
Something like:
Refer to the Key-Value Coding Programming Guide