I have a UITableViewController which pushes a UIViewController and I need to pass two NSDates and a BOOL from that child view controller back to the table view controller.
How could I do this? Let me know if I am not being clear or you need more explanation.
I’d appreciate any help, thanks.
Using a delegate is the proper way of passing info from one controller to another.
Generally, what you want to do is to declare a protocol in your
UITableViewControllerheader, implement it, and then init theUIViewControllerwith a delegate.In a nutshell, your
UITableViewController .hfile should have something like this:Then, you ought to implement the above mentioned class doing whatever you want to do with the dates in your
UITableViewController .mfile.In your
UIViewController, you could (alternative at the end) define a custom init method:First, define a delegate property in your .h, and a custom init method, then implement it in your .m with something like this:
Next, when you need to pass the dates to your
UITableViewController, just use[self.delegate setDateOne:one dateTwo:two];There are more ways of doing this, including skipping the custom init method and just setting the delegate after you create a
UIViewController:It’s more of a personal preference style.
I’ve probably messed up the code (and forgotten a few bits) because I’m writing this off the top of my head, but it should be good enough to get you started.