[swift]Segue與ViewController連接之兩種方法

Jacob 黃炬楷
Jul 22, 2017 · 2 min read

第一種方法非常簡單,甚至連coding都不需要。

重點是要按住Control拖曳至另一個ViewController,然後選show,就完成啦!

第二種方法,需要一點Coding,透過 Identifier連接。

主要不同是,這次從原本的ViewController上方三個小圖示中,最左邊(如下圖)的地方,拖曳至另一個ViewController,同樣也是點擊show。

接著,在兩個ViewController中間的會出現一個箭頭的segue,並點擊。

於左邊的Identifier輸入goToSecond。

最後,打開ViewController,建立Button的@IBAction如下,應該就沒問題囉!

@IBAction func button(_ sender: UIButton) {     performSegue(withIdentifier: "goToSecond", sender: self)}
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade