1.本例中,我在view1使用了导航,view2中没有使用导航.这就做一个对比.
先看看 代理的.h文件吧
#import <UIKit/UIKit.h>
@class LCFirstViewController,LCSecondViewController;
@interface LCAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) LCFirstViewController *firstViewController;
@property (strong, nonatomic) LCSecondViewController *secondViewController;
.m文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
_firstViewController = [[LCFirstViewController alloc]init];
_firstViewController.title =@"第一view";
UINavigationController *firstNav = [[UINavigationController alloc]initWithRootViewController:_firstViewController];
_secondViewController = [[LCSecondViewController alloc]init];
NSArray *viewArr = [NSArray arrayWithObjects:firstNav,_secondViewController, nil];
UITabBarController *tabBarVC = [[UITabBarController alloc]init];
tabBarVC.viewControllers = viewArr;
self.window.rootViewController = tabBarVC;
[self.window makeKeyAndVisible];
return YES;
}
总结:实现的原理是什么呢?
我们把一个带导航的控制器 和一个UiviewController 放到数组中,最终设置 tabbarVC的ViewCOntrollers 为该数组.
最后设置window的root为 tabbarVC,这样子 带导航不带导航的都有了~