swift3 - Pass variable to next View Controller -


i want pass variable 1 view controller another. first view controller looks , segue gets triggered correctly , new view controller gets displayed.

@ibaction func testbutton(_ sender: any) {      let timervc = timerviewcontroller()      timervc.secondspassed = textfield_seconds.text!      navigationcontroller?.pushviewcontroller(timervc, animated: true)  } 

on next view controller (timerviewcontroller) declared variable in class header

var secondspassed:string! 

and in viewdidload want print value console , receive 'nil'.

i looked through various tutorials seem not find correct answer work.

anyone around clue?

thanks in advance...

if using segue, can remove line presents controller (you don't seem have navigationcontroller anyway):

navigationcontroller?.pushviewcontroller(timervc, animated: true) 

now correct way pass data vc using segues this:

override func prepare(for segue: uistoryboardsegue, sender: any?) {     if let vc = segue.destination as? timerviewcontroller {         vc.secondspassed = textfield_seconds.text!     } } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -