簡體   English   中英

如何訪問其他類中的屬性/方法

[英]How to access properties/methods in other classes

我有一個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和切換選項卡?

嘗試在根控制器中實現協議,並在您的類中確認該協議。 另一種方法是使用通知。

希望能有所幫助。

還要檢查這個帖子: 從另一個調用類的函數-的OBJÇ

如果你使用@synthesize在您的實現,那么你實現什么有公共套getter和setter。

這意味着,如果您可以在此處獲得指向RootViewController的指針,則還可以對它的.arTabBarController屬性進行任何.arTabBarController

您也可以使用“ keyPaths”。 就像是:

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

請參閱《 鍵值編碼編程指南》

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM