iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 7
0
Mobile Development

《菜鳥のSwift》持續30天開發挑戰系列 第 7

《DAY 7》新增手機頁面

首先在 Main.storyboard 從元件庫中拖曳出 View Controller。

在資料夾內新增一個子類別為 UIViewController 的檔案並設定名稱。
https://ithelp.ithome.com.tw/upload/images/20200920/20129680Z6dtjLZO3V.png

將拖曳出的 View Controller 的 Class 設為剛剛取好的檔名,順便放張圖點綴一下畫面。
https://ithelp.ithome.com.tw/upload/images/20200920/20129680oEofisY8oZ.png

先點選第一個 View Controller 拉藍線到第二個手機頁面上再點選 Show。
https://ithelp.ithome.com.tw/upload/images/20200920/20129680y88h6nGs52.png

手機頁面之間會多出一條有箭頭的線,我們可以點選它並為它取上識別碼。
https://ithelp.ithome.com.tw/upload/images/20200920/20129680rhoYS1tsjB.png

假設我要從第一個畫面的表格中跳到第二個畫面,可以在 ViewController.swift 內寫一個 func。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    performSegue(withIdentifier: "toSecondView", sender: nil) // 如果要設定成只有其中一個儲存格被點選才跳頁,請自己加入判斷式
}
  • 跳至第二個畫面的樣子。
    https://ithelp.ithome.com.tw/upload/images/20200920/20129680WW1qgDfPAw.png

  • 第二個頁面的 Presentation 設為 Full Screen,可以變成全螢幕。
    https://ithelp.ithome.com.tw/upload/images/20200921/20129680up0c0zruvy.png


上一篇
《DAY 6》使用表格元件
下一篇
《DAY 8》切換手機畫面
系列文
《菜鳥のSwift》持續30天開發挑戰30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言