ios - Swift Pass data between files -
i need pass variable value file file. try code doesn't working, on destination data value it's nil :
func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) { var destview: otpvc = segue.destinationviewcontroller as! otpvc destview.datapassed = "\(mobile)" } otpvc destination viewcontroller , mobile variable want transport otpvc view. in advance.
you're doing wrong somewhere.
if pushing/presenting next otpvc programatically, prepareforsegue not called , therefore destview.datapassed nil. prepareforsegue works if define view controller transitions in storyboard, or call performsegue in code transition.
for example, pushing:
if let navigationcontroller = self.navigationcontroller { let nextscreen = otpvc() nextscreen.datapassed = "\(mobile)" navigation.pushviewcontroller(nextscreen) } or presenting:
let nextscreen = otpvc() nextscreen.datapassed = "\(mobile)" self.presentviewcontroller(nextscreen, animated: true, completion: nil)
Comments
Post a Comment