Ios--appdelegate Toggle Root View Rootviewcontroller (the Most common scenario is the first boot jump to navigation viewcontroller)
Last Update:2015-05-07
Source: Internet
Author: User
<span id="Label3"></p><p><p>Reprinted from http://blog.csdn.net/wanggsx918/article/details/25215183</p></p><p><p><span style="font-size: 18px;">1. Add a toggle method in Appdelegate switchrootviewcontroller:</span></p></p><p><p></p></p><pre>-(BOOL) application: (uiapplication *) application didfinishlaunchingwithoptions: (nsdictionary *<span style="color: #000000;"><span style="color: #000000;">) launchoptions {self.window</span></span>=<span style="color: #000000;"><span style="color: #000000;">[[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>([[nsuserdefaults standarduserdefaults] boolforkey:<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">Firstlaunch</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">]) { </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">start the navigation page for the first time</span></span>NSLog (<span style="color: #800000;"><span style="color: #800000;">@"</span></span><span style="color: #800000;"><span style="color: #800000;">wanggsx: first time start</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;">); Viewcontroller</span></span>*appstartcontroller =<span style="color: #000000;"><span style="color: #000000;">[[viewcontroller alloc] init]; Self.window.rootViewController</span></span>=<span style="color: #000000;"><span style="color: #000000;">appstartcontroller; [self.window addSubview:appStartController.view]; } </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">Else</span></span><span style="color: #000000;"><span style="color: #000000;"> { </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Open the Select site interface</span></span><span style="color: #000000;"><span style="color: #000000;">[self switchrootviewcontroller]; } [self.window makekeyandvisible]; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">YES; } </span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">Toggle Rootviewcontroller</span></span>- (<span style="color: #0000ff;"><span style="color: #0000ff;">void</span></span><span style="color: #000000;"><span style="color: #000000;">) Switchrootviewcontroller {self.window.rootViewController</span></span>=<span style="color: #000000;"><span style="color: #000000;">nil; Choosemodeviewcontroller</span></span>* crbrandsviewcontroller=<span style="color: #000000;"><span style="color: #000000;">[[choosemodeviewcontroller alloc] init]; Uinavigationcontroller</span></span>*brandsnavigationcontroller =<span style="color: #000000;"><span style="color: #000000;">[self customcontrollerwithrootviewcontroller:crbrandsviewcontroller]; Self.viewcontroller</span></span>=<span style="color: #000000;"><span style="color: #000000;">brandsnavigationcontroller; Self.window.rootViewController</span></span>=<span style="color: #000000;"><span style="color: #000000;">self.viewcontroller; } </span></span></pre><p><p></p></p><p><p></p></p><p><p>2. Call the method in Appdelegate in Viewcontroller that needs to switch the root view:</p></p><p><p></p></p><pre><pre> -(ibaction) gotomainview: (<span style="color: #0000ff;">ID</span><span style="color: #000000;">) sender { [[nsuserdefaults standarduserdefaults] setbool:no forkey: </span> <span style="color: #800000;">@ "</span><span style="color: #800000;">firstlaunch</span><span style="color: #800000;">"</span><span style="color: #000000;">]; [(appdelegate</span>*) [uiapplication sharedapplication]. <span style="color: #0000ff;">Delegate</span> <span style="color: #000000;">switchrootviewcontroller]; </span></pre></pre><p><p></p></p><p><p>Ios--appdelegate Toggle Root View Rootviewcontroller (the Most common scenario is the first boot jump to navigation viewcontroller)</p></p></span>