Passing variables between Storyboards without Segues - Swift

喜你入骨 提交于 2019-11-29 02:31:09

I'm assuming that the viewController that you want to pass the data to is a custom viewController. In that case, use this amended code here:

var storyboard = UIStoryboard(name: "IDEInterface", bundle: nil)
var controller = storyboard.instantiateViewControllerWithIdentifier("IDENavController") as! MyCustomViewController

controller.exercisedPassed = "Ex1"

self.presentViewController(controller, animated: true, completion: nil)

your question is not very clear, as far as i have understood

//1
//create a variable in "IDENavController"
//e.g 
var someVariable = @""

//2
var controller = storyboard.instantiateViewControllerWithIdentifier("IDENavController") as!       UIViewController
controller.someVariable = [assign your variable]

//3
self.presentViewController(controller, animated: true, completion: nil)

Try this. This worked for me.

var storyboard = UIStoryboard(name: "IDEInterface", bundle: nil)
var controller = storyboard.instantiateViewControllerWithIdentifier("IDENavController") as! YourDestinationViewControllername
// Add your destination view controller name and Identifier

// For example consider that there is an variable xyz in your destination View Controller and you are passing "ABC" values from current viewController.

controller.xyz = "ABC"

self.presentViewController(controller, animated: true, completion: nil)

Hope this will be helpful.

For those who are looking for the Swift 3/4 answer:

let storyboard = UIStoryboard(name: "IDEInterface", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "IDENavController") as! CustomViewController

controller.yourVariable = "abc"

self.present(controller, animated: true, completion: nil)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!