在 iOS 的開(kāi)發(fā)過(guò)程中,可以使用 Stroyboard 來(lái)管理多個(gè) ViewController钮糖。創(chuàng)建項(xiàng)目的時(shí)候,XCode 默認(rèn)會(huì)幫我們生成一個(gè) Main.stroyboard 的文件。我們可以將多個(gè) ViewController 放入一個(gè) Stroyboard 中。但是在一個(gè) Stroyboard 中放入過(guò)多的 ViewController 時(shí)男杈,會(huì)出現(xiàn)很多問(wèn)題,比如:打開(kāi)文件的速度慢调俘,多人編輯容易造成沖突伶棒,修改的時(shí)候難度增加旺垒,等等。這時(shí)我們就需要將相關(guān)的 ViewController 放在一個(gè)單獨(dú)的 Stroyboard 中肤无,也就是將一個(gè) Stroyboard 拆分成多個(gè)先蒋。
多個(gè) Stroyboard 中的跳轉(zhuǎn),我們可以使用代碼實(shí)現(xiàn)舅锄,那如何使用拖拽連線的方式實(shí)現(xiàn)呢鞭达?
實(shí)現(xiàn)步驟
- 在 XCode 已經(jīng)幫我們創(chuàng)建了一個(gè) Main.storyboard 的基礎(chǔ)上,在創(chuàng)建一個(gè) Second.storyboard皇忿。
- 在 Main.storyboard 的 Storyboard Entry Point 的 ViewController 中創(chuàng)建并約束一個(gè)用于跳轉(zhuǎn)到 Button(命名為:Jump To Second Storyboard)
Storyboard Entry Point 是進(jìn)入當(dāng)前 Storyboard 開(kāi)始的地方,在 XCode 中用藍(lán)色的箭頭表示
- 在 Main.storyboard 中拖拽出一個(gè) Storyboard Reference坦仍,設(shè)置其 Storyboard 為我們創(chuàng)建的 Second.storyboard鳍烁。
- 按住 control 鍵,從用于跳轉(zhuǎn)的 Button 拖拽到剛創(chuàng)建的 Storyboard Reference 上繁扎,選擇跳轉(zhuǎn)方式幔荒。
- 在 Second.storyboard 中拖拽出一個(gè) ViewController, 并設(shè)置為最初的 ViewController,設(shè)置完之后梳玫,ViewController 的左邊就會(huì)多出一個(gè)箭頭爹梁。
設(shè)置 ViewController 的 Is Initial View Controller 屬性,也就是設(shè)置 Storyboard 的入口(Storyboard Entry Point)提澎。一個(gè) Storyboard 中只能勾選一個(gè) ViewController 的 Is Initial View Controller 屬性姚垃,也就是只有一個(gè)入口 ViewController。
- 完成盼忌,開(kāi)始運(yùn)行測(cè)試吧积糯。