Passing data between StoryBoards

Passing Data between StoryBoards

Now we have already seen how we can pass data from one VC to another VC using Segue but what to do when we have to pass data between 2 ViewControllers which are in different StoryBoards where we cannot drag the Segue from one VC to another.

So in this type of cases we wont be able to drag Segue but instead we have to vcreate objects to pass data between storyboards

Consider 2 storyBoards “Main” and “Qwerty” and you have to pass data in ViewController from “Main” storyboard to View Controller in “Qwerty” Storyboard

So all you have to do is Instantiate the ViewController and pass the value to it




Consider the scene

StoryBoard1 – “Main” StoryBoard

StoryBoard1 – “Qwerty”StoryBoard

ViewController1 – A ViewController in StoryBoard1

ViewController2 – A ViewController in StoryBoard2

PassingData = The String Containing “Monday is Boring” in ViewController1

recievedData = The variable in ViewController in which values will be passed

viewcontrl – Storyboard identifier for ViewController2

 




JUST WRITE THIS CODE AFTER THE ABOVE SETTINGS AND YOU FILL SE THAT THE VALUES ARE FETCHED IN THE ViewController2

let storyboard = UIStoryboard(name: “Qwerty”, bundle: nil)

let vc = storyboard.instantiateViewController(withIdentifier: “filter”) as! VC2

vc.recievedData = PassingData

vc.modalPresentationStyle = .overFullScreen

vc.modalTransitionStyle = .crossDissolve

self.present(vc, animated: true, completion: nil)

 


Article written and submitted by: Niket Singh

Leave a Reply

Your email address will not be published. Required fields are marked *