0

I have two view controllers VC1 and VC2. I pass a value from VC1 to VC2 through prepareForSegue method. and when I receive that value in VC2 I multiply it by 10.

what I want to do is, after multiplying that value by 10 in VC2 I want to return it back to VC1.

such scenario could be done using Intents and BroadcastReceiver. how can I do that in iOS using objective.c?

Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • Use delegates Google about it issue solved. – Tushar Sharma Aug 04 '17 at 17:35
  • There are a few options to share data with other objects: delegation, notification, properties, singletons.. – Marcio Romero Patrnogic Aug 04 '17 at 17:37
  • Possible duplicate of [Passing Data between View Controllers](https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – dan Aug 04 '17 at 17:40
  • @Marcio Romero Patrnogic OP question says he wants one to one process for passing values . Which is best solved by delegates. – Tushar Sharma Aug 04 '17 at 17:40
  • I wouldn't be so sure about .. "best solved by gelegates".. there are many scenarios when other solutions could be better.. What I am trying to say is that there are a few options out there that he should evaluate before making a decision – Marcio Romero Patrnogic Aug 04 '17 at 17:45
  • Go for Delegates. See this for more info: https://teamtreehouse.com/community/how-to-pass-values-between-multiple-view-controllers-using-delegate-protocol – Sivajee Battina Aug 04 '17 at 17:45
  • Lets say he has an object "Person", he passes the reference from VC1 to VC2. Then he sets Person.Name = "RandomName". He doesnt need to write any code, because he has updated the same person. VC1 has the reference to that person and he will see the change without extra code. – Marcio Romero Patrnogic Aug 04 '17 at 17:48
  • @Marcio Romero Patrnogic it's a general thumb rule delegates - one to one , Notification -: one to many , KVO - much more you have here. – Tushar Sharma Aug 04 '17 at 17:48
  • Then what if its an object and he passes the reference.. its way easier than delegation? my point is it depends on what he needs – Marcio Romero Patrnogic Aug 04 '17 at 17:52
  • @MarcioRomeroPatrnogic so, I think you recommend KVO over delegates, don't you? – Amrmsmb Aug 04 '17 at 17:58
  • I am not suggesting KVO.. Its just simple OOP – Marcio Romero Patrnogic Aug 04 '17 at 18:01
  • @TusharSharma I used the delegate as you suggested, but would you please check this question:https://stackoverflow.com/questions/45513017/how-to-call-the-required-method-in-a-delegate-in-the-implementation-file. I have a problem in calling the method of the delegate – Amrmsmb Aug 04 '17 at 18:27
  • I am not objective -c guy but this might help-: https://stackoverflow.com/questions/626898/how-do-i-create-delegates-in-objective-c – Tushar Sharma Aug 04 '17 at 18:34
  • @SivajeeBattina I used delegate as you suggested but I have a problem calling the method of the delegate, would you please have a look at this question:https://stackoverflow.com/questions/45513017/how-to-call-the-required-method-in-a-delegate-in-the-implementation-file – Amrmsmb Aug 04 '17 at 18:37
  • @user2121 Avoid poisting multiple questions with the same issue. You have made an issue here https://stackoverflow.com/questions/45513017/how-to-call-the-required-method-in-a-delegate-in-the-implementation-file . You can instead update your question with the suggestions and get an answer in the same thread. –  Aug 04 '17 at 20:52

0 Answers0