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
Post a Comment