I am new to iOS development and having a fundamental question as how i can re-use same view controller from two different view controllers to perform a specific function.
Here is my problem. Say we have three view controllers A, B and C. And C performs a specific function and it's output i want to use in both A and B.
Say A, has two edit box A1 and A2 and a button "Call C", A1 is edit box that user fills in and to take input for A2, we have to call C by pressing "Call C" button that i have segued in storyboard.
Similarly B, has two edit box B1 and B2 and also a button "Call C". B1 is edit box that user fills in and to take input for B2, we have to call C by pressing "Call C" button that i have segued in storyboard.
Essentially i want to make use of C for two different view controllers where C will return some string to calling view that i can fill in B2 or C2 edit boxes.
Here are two ways to unwind:
Method - A:
Programmatically you can call performSegueWithIdentifier to caller view controller and return to it, but in this process called view controller (i.e. A or B) gets re-created, so input that may have been done by user on control A1 or C1 is lost as A and B views are re-created.
So i can programmatically unwind but state is lost of calling view controller as it gets re-created.
Method - B:
In both A and B i create unwind methods like:
-(IBAction) receiveDataFromCtoA:(UIStoryboardSegue *)segue
-(IBAction) receiveDataFromCtoB:(UIStoryboardSegue *)segue
respectively.
But in view C, i can only unwind in Exit to either of the two functions however it does allow me to retain value of calling view controller controls A1 / C1.
So unwinding from Exit works as expected, but i can only unwind to either of the two and thus i can't reuse view controller C for both.
So whole point is how you can make use of a view controller which takes some input, performs some calculation and return results and can be used by any calling view.
I did look at following post:
Unwind segues for 2 View Controllers
But it does not answer.
Any help is appreciated.