1、WYYNavigationController
#import"WYYNavigationController.h"
@implementationWYYNavigationController
-(void)viewDidLoad{
[superviewDidLoad];
}
-(void)didReceiveMemoryWarning{
[selfdidReceiveMemoryWarning];
}
@end
2锦茁、自定義TabBarController攘轩,WYYTabBarController
//
//WYYTabBarController.m
//test1
//
//Created by? chengyou on 16/1/18.
//Copyright ?? 2016年wuyingying. All
rights reserved.
//
#import"WYYTabBarController.h"
@implementationWYYTabBarController
-(void)viewDidLoad{
[superviewDidLoad];
[selfsetUpAllChildViewController];
}
-(void)? setUpAllChildViewController{
//1.添加第一個控制器
WYYOneViewController*oneVc = [[WYYOneViewControlleralloc]init];
[selfsetUpAllChildViewController:oneVcimage:[UIImageimageNamed:@"tab_home_icon"]title:@"首頁"];
//2.添加第二個控制器
WYYTwoTableViewController*twoVc = [[WYYTwoTableViewControlleralloc]init];
[selfsetUpAllChildViewController:twoVcimage:[UIImageimageNamed:@"js"]title:@"通訊錄"];
//3.添加第三個控制器
WYYThreeTableViewController*threeVc = [[WYYThreeTableViewControlleralloc]init];
[selfsetUpAllChildViewController:threeVcimage:[UIImageimageNamed:@"qw"]title:@"辦公"];
//4.1加載storyboard,這里僅僅是加載名稱為WYYFourViewController的storyBoard,并不會創(chuàng)建storyBoard中的控制器和空間
UIStoryboard*storyBoard = [UIStoryboardstoryboardWithName:@"WYYFourViewController"bundle:nil];
//4.2創(chuàng)建storyBoard中箭頭指向的控制器(初始控制器)
WYYFourViewController*fourVc =
[storyBoardinstantiateInitialViewController];
//4.3添加第四個控制器
[selfsetUpAllChildViewController:fourVcimage:[UIImageimageNamed:@"user"]title:@"設置"];
}
#pragma mark --添加一個子控制器的方法
-(void)setUpAllChildViewController:(UIViewController*)viewController
image:(UIImage*)image title:(NSString*)title{
UINavigationController*navC = [[UINavigationControlleralloc]initWithRootViewController:viewController];
navC.title= title;
navC.tabBarItem.image= image;
[navC.navigationBarsetBackgroundImage:[UIImageimageNamed:@"commentary_num_bg"]forBarMetrics:UIBarMetricsDefault];
viewController.navigationItem.title= title;
[selfaddChildViewController:navC];
}
@end
3码俩、WYYViewController
//
//WYYViewController.m
//test1
//
//Created by? chengyou on 16/1/18.
//Copyright ?? 2016年wuyingying. All
rights reserved.
//
#import"WYYViewController.h"
@implementationWYYViewController
-(void)viewDidLoad{
//如果控制器A的View成為控制器B的View的子控件度帮,那么A控制器成為B控制器的子控制器
WYYTabBarController*tabBarVc = [[WYYTabBarControlleralloc]init];
//添加WYYTabBarController為子控制器
[selfaddChildViewController:tabBarVc];
}
@end
4、AppDelegate.m
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Override point for customization after application
launch.
//1.創(chuàng)建窗口
self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];
//2.設置窗口的根控制器
WYYTabBarController*dragVc = [[WYYTabBarControlleralloc]init];
self.window.rootViewController= dragVc;
//3.顯示窗口
[self.windowmakeKeyAndVisible];
returnYES;
}