最近做一個(gè)練習(xí)項(xiàng)目屋摔,在做用戶(hù)引導(dǎo)頁(yè)的時(shí)候需要在播放完引導(dǎo)頁(yè)之后跳轉(zhuǎn)到navigationViewController
實(shí)現(xiàn)代碼如下:
//1薛匪,首先獲得當(dāng)前工程的storyboard文件四敞,方法如下:
UIStoryboard *story = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
//2移剪,拿到帶有指定標(biāo)簽的viewcontroller:
這個(gè)需要在storyboard中設(shè)置一下將要跳轉(zhuǎn)到的頁(yè)面的id号杏,在storyboard可以找到這個(gè)設(shè)置誓斥,填一個(gè)id即可
LCHMyNavigationController *nvc = [story instantiateViewControllerWithIdentifier:@"LCHNAVCONTROLLER"];
//3只洒,最后做一下跳轉(zhuǎn)即可:
[self presentViewController:nvc animated:YES completion:nil];
這樣跳過(guò)去的頁(yè)面,會(huì)完整保留storyboard種定義的外觀以及被彈出頁(yè)面與其他storyboard中頁(yè)面的跳轉(zhuǎn)關(guān)系劳坑,
還有對(duì)應(yīng)的xib文件中定義的空間布局红碑,不會(huì)丟失任何信息,但如果是用代碼new出來(lái)或者alloc一個(gè)想要跳轉(zhuǎn)過(guò)去的ViewController泡垃,
然后再push出來(lái)析珊,那么彈出來(lái)的頁(yè)面就會(huì)丟失xib文件的布局和storyboard定義的頁(yè)面關(guān)系。完全是一個(gè)新的頁(yè)面實(shí)例蔑穴,
不帶有任何storyboard和xib的內(nèi)容忠寻,無(wú)法實(shí)現(xiàn)想要的效果。
最關(guān)鍵的是由于UINavigationController是繼承自UIViewController的存和,
所以這個(gè)方法還可以跳轉(zhuǎn)至storyboard中帶有指定id的UINavigationController上奕剃,
這樣就可以實(shí)現(xiàn)從一個(gè)UINavigationController的某個(gè)界面跳至另外一個(gè)UINavigationController的根頁(yè)面上衷旅,
也就是可以在兩個(gè)storyboard中擺放的UINavigationController之間進(jìn)行跳轉(zhuǎn)。
- 附:其他跳轉(zhuǎn)到storyboard和xib的方式
//1纵朋,跳轉(zhuǎn)到xib 假設(shè)有一個(gè)按鈕柿顶,這個(gè)按鈕就是實(shí)現(xiàn)跳轉(zhuǎn)的,那么在這個(gè)按鈕的點(diǎn)擊事件中操软,代碼可以這樣寫(xiě)嘁锯。
AViewController *a1= [[AViewController alloc]initWithNibName:@”AViewController” bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:a1 animated:YES];
//2,跳轉(zhuǎn)到storyboard 如上,代碼可以這樣寫(xiě)
UIStoryboard *sb=[UIStoryboard storyboardWithName:@”A” bundle:nil];
[self presentViewController:[sb instantiateInitialViewController] animated:YES completion:nil];