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?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
You need to
reference
yoursecondViewController
, and create an object for it.object2.thatArray
would have the contents of the array. Make sure that the array retains it's values when you leave that view controller (or you can create that array in yourAppDelegate
so that it can be accessed by all viewControllers).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: