I have two view controllers. I’m on first, and when I press the button, second view controller is pushed onto the stack of navigation controller. Here, in second view controller I have a table view and when I tap on some rows, they are selected (like checkboxes) and some data related to that rows are added to an array. Now when I’m done with selecting, I want to go back to the first view controller and use that array. How to do that? Now my app works like this: I have a delegation protocol, then object in which I have the property array, and I can access that object and its array from whole app…but I don’t really like that. Is this correct/best/simplest way to do that?
Share
Delegation is the correct pattern to use here, but what you describe isn’t so much delegation as it is using a global variable. Perhaps you’re storing globals in your App Delegate — generally something you can avoid if you can.
Here’s a rough outline of what the code should look like:
SecondViewController.h:
SecondViewController.m:
FirstViewController.h:
FirstViewController.m: