[問題] swift UINavigationController 傳遞參數

看板MacDev作者 (蔥頭)時間7年前 (2017/01/15 18:23), 7年前編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
請問一下 如果不使用storyboard開發(已經移除) 單純用純程式碼的方式來進行開發(直接用UINavigationController()來建立元件) 那請問不同的UIViewController 要如何 傳遞參數? 我上網查資料大部分傳遞都需要使用到stoyboard identifier 如下 func onClick() { // 這邊就會發說錯誤, 錯誤訊息為沒有ShowArticle storyboard self.performSegue(withIdentifier: "ShowArticle", sender: "message") self.navigationController?.pushViewController(myArticleViewController(), animated: true) } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if(segue.identifier == "ShowArticle") { let controller = segue.destination as! ArticleViewController controller.parameter = sender as! String } } 如果沒有stoyboard ideentifier 純程式碼開發的方式進行傳送嗎? 註 : 畫面切換方式我使用UINavigationController來進行切換 謝謝各位 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.34.181.227 ※ 文章網址: https://www.ptt.cc/bbs/MacDev/M.1484475802.A.760.html ※ 編輯: tas72732002 (114.34.181.227), 01/15/2017 18:27:45

01/15 18:32, , 1F
純code,就直接初始化一個
01/15 18:32, 1F

01/15 18:39, , 2F
let viewC = DTViewController(balabala: "")
01/15 18:39, 2F

01/15 18:39, , 3F
這樣就可以了
01/15 18:39, 3F
文章代碼(AID): #1OUqsQTW (MacDev)