iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 9
2
Mobile Development

IOS App開發學習日誌系列 第 9

Day9 Storyboard Segue跳轉

今天要說的是storyboard頁面建立以及跳轉的部分
首先我們在library拉出viewcontroller頁面到storyboard
https://ithelp.ithome.com.tw/upload/images/20190925/20120980dokwyFnAgR.png
到左側的檔案欄位建立新檔案
https://ithelp.ithome.com.tw/upload/images/20190925/20120980a9qyFPR72j.png
選擇cocoa touch class並選擇UIViewController欄位並且取名
https://ithelp.ithome.com.tw/upload/images/20190925/20120980LULThGQhL1.png
https://ithelp.ithome.com.tw/upload/images/20190925/20120980ZBMjoSzHr6.png
點擊新增的viewcontroller點選右方的identity按鍵後可以在class欄位看到剛剛建立的檔案並點擊選取
https://ithelp.ithome.com.tw/upload/images/20190925/2012098029pPpvYkec.png

segue

通常app有多個畫面做切換,segue的功能可以幫助我們完成跳轉

首先我們在兩個頁面分別加上元件如下圖
https://ithelp.ithome.com.tw/upload/images/20190925/20120980GivnazDQry.png
按住主畫面的頁面並拖到想要跳轉的頁面上放開
https://ithelp.ithome.com.tw/upload/images/20190925/20120980fFShcUZyDo.png
會產生一個箭頭的圖示,點擊後在右方的show the attributes inspector中的class欄位取名
https://ithelp.ithome.com.tw/upload/images/20190925/20120980nqtT1cN72d.png
接著點擊右上方雙圈按鍵
https://ithelp.ithome.com.tw/upload/images/20190925/20120980zr1VfSJIB7.png
按住ctrl將button元件欄位拉至右方程式碼如下圖跳出欄位,再填上這個事件的名字
https://ithelp.ithome.com.tw/upload/images/20190925/20120980JDWLiZ7CcH.png
在action func中加入performSegue()的方法,withIdentifier後填上segue名稱,sender的部分填上nil
https://ithelp.ithome.com.tw/upload/images/20190925/20120980s4Xb6aoIvK.png
最後打開模擬器(快捷鍵command+R),按下跳轉按鍵即可完成頁面跳轉


上一篇
Day8 AutoLayout(二)
下一篇
D10 NavigationController
系列文
IOS App開發學習日誌30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言