ios - Access Variables of ViewController Before Popping To It -
i have home button triggers code when pressed. need change variable within viewcontroller popping before pop it. there way this?
func gohome(){ let switchviewcontroller = self.navigationcontroller?.viewcontrollers[1] as! uiviewcontroller self.navigationcontroller?.poptoviewcontroller(switchviewcontroller, animated: true) } this how thought go no variables of viewcontroller appear in autocomplete window.
switchviewcontroller.x = 5 any information on how go and/or why isn't working appreciated.
you're setting switchviewcontroller generic uiviewcontroller, has no variable .x.
you should set correct class, in case whatever named class has 'x' variable:
let switchviewcontroller = self.navigationcontroller?.viewcontrollers[1] as! switchviewcontroller switchviewcontroller.x = 5 in case i've used class name switchviewcontroller, means you'd need .swift class file so:
import uikit class switchviewcontroller: uiviewcontroller { var x: int! override func viewdidload() { super.viewdidload() } override func didreceivememorywarning() { super.didreceivememorywarning() } }
Comments
Post a Comment