I'm new to iOS Development, and Swift. And many of the resources I've found on the Google are written in Objective-C, which I am not familiar also.
I have two view Storyboards, S1 and S2. Each of them have at least 1 View Controller, VC1 and VC2 respectively. I go from S1 to S2 using a Gesture Recognizer, not a Segue. On S2, I select a data taken from a Table View. When I press a value from the list on the table, I would like to send that values back to S1.
What's the best way to do this using Swift? Thanks!
You can use NSNotificationCenter for that
Add Oberver in S1
Call it from S2 tableview click and pass userInfo.
You can use Custom protocol techniques.
Write in S1
Write in S2
Hope it may help full for you.
The preferred way for this would be to use delegation, e.g. tell
S2
to report back toS1
.Another answer tried to make this point already, yet didn't make clear what is going on.
The idea is to have
S2
hold a reference toS1
and report back. It comes in handy that you are not using segues; they would make it minimally more complex.Protocol
You can do so by creating a protocol for communication:
S1
Within
S1
, you implementReportBackProtocol
like so:And assign your
S1
instance as a delegate of yourS2
instance where you create it, before you present it:S2
In
S2
, wherever you have compiled your values (let's call themx
) and are ready to send them back:You also need to add the delegate instance variable to
S2
like so:This should do the trick; please let me know if you run into problems or do not understand parts of the concept.