UITabBarController+UINavigationController+UIViewCOntroller,多級控制器的創建。
#pragma mark - 創建視圖控制器
- (void) createViewControllers {
//1) 創建4個視圖控制器
TrendsViewController *trendsVC = [[TrendsViewController alloc] init];
FindViewController *findVC = [[FindViewController alloc] init];
MessageViewController *messageVC = [[MessageViewController alloc] init];
MyViewController *myVC = [[MyViewController alloc] init];
//2) 將上述的4個視圖控制器添加到一個數組中
NSArray *viewControllerArrays = @[ trendsVC, findVC, messageVC,myVC ];
//3) 設置title
NSArray *titleArray = @[ @"動態", @"發現", @"消息", @"我的"];
//4) 使用一個空的可變數組存儲導航欄
NSMutableArray *navigationArray = [NSMutableArray array];
//5) for循環創建導航欄
for (int i = 0; i < viewControllerArrays.count; i++) {
//a) 獲取UIViewController
UIViewController *viewCtrl = viewControllerArrays[i];
//b) 設置標題
viewCtrl.title = titleArray[i];
//c) 設置導航欄
//說明:第0個導航欄做特殊處理,使用自定義的
if (i == 0) {
//1) 自定義導航欄
TrendsNavigationController *trendsNavigation = [[TrendsNavigationController alloc] initWithRootViewController:viewCtrl];
//2) 添加到數組中
[navigationArray addObject:trendsNavigation];
} else {
//1) 系統導航欄
UINavigationController *navigationCtrl = [[UINavigationController alloc] initWithRootViewController:viewCtrl];
//2)添加到數組中
[navigationArray addObject:navigationCtrl];
}
}
//6) 使用標籤控制器來控制這些導航欄
self.viewControllers = navigationArray;
}