我正在開發一個基於UITabbar和視圖層次結構的應用程序,如下所示。從UIVIewController訪問UITabBarController
的UITabBarController ----> ----的UINavigationController>的UIViewController
我需要從UIIVewController訪問的UITabBarController。但以下屬性總是返回nil。
self.tabBarController和self.navigationController.tabBarController
有沒有直接從孩子的viewController訪問Tabbarcontroller不使用的AppDelegate的方法嗎?
@implementation HomeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
self.title = @"Home";
self.navigationItem.title = @"Home";
self.tabBarItem.image = [UIImage imageNamed:@"TabBarHome"];
UITabBarController *tab = self.tabBarController;
UITabBarController *tab1 = self.navigationController.tabBarController;
UITabBarController *tab2 = self.navigationController.presentingViewController;
}
return self;
}
它可能只使用'從嵌入在'UITabBarController'任何'UIViewController' self.tabBarController',檢查@ Rashad的回答低於 – nburk