*keyWindow指向的視圖才可以被看到缨叫,如果指向其他的視圖,那么原來的視圖會被釋放掉
1.獲取到 Storyboard
1.1通過名字
UIStoryboard*storyboard = [UIStoryboardstoryboardWithName:@"Main"bundle:nil];
1.2通過 self.storyboard
UIStoryboard*storyboard =self.storyboard;
2.獲取到 storyboard 的視圖控制器
2.1通過 Storyboard ID
self.view.window.rootViewController= [storyboardinstantiateInitialViewController];
self.view.window.rootViewController= [storyboardinstantiateViewControllerWithIdentifier:@"viewController"];
3.獲取到使用 xib 創(chuàng)建視圖控制器
MyViewController*vc = [[MyViewControlleralloc]initWithNibName:@"MyViewController"bundle:nil];
4.代碼設(shè)置導(dǎo)航欄的根視圖控制器
MyNavigationController*nv = [[MyNavigationControlleralloc]initWithRootViewController:vc];
5.通過 keyWindow 來獲取到視圖控制器
_playingVC= [[UIApplicationsharedApplication].keyWindow.rootViewController.storyboardinstantiateViewControllerWithIdentifier:@"ViewController"];
6.keyWindow 來設(shè)置根視圖控制器藕咏,可以直接跳轉(zhuǎn)頁面
[UIApplicationsharedApplication].keyWindow.rootViewController= [storyboardinstantiateInitialViewController];
7.自己的window
WelComeViewController*vc = [self.window.rootViewController.storyboardinstantiateViewControllerWithIdentifier:@"WelComeViewController"];
8.拿到XIB創(chuàng)建的UIView的引用
SendMessageView*vc = [[NSBundlemainBundle]loadNibNamed:@"SendMessageView"owner:selfoptions:nil][0];