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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -