views:

75

answers:

1

Basically I have a hierarchy of locations: country, state/prov, city.

I want to present an "Add Location" modal table using a delegate.

I realize the best way to do this is to present my top level elements in a TableView, and if they are selected, I want to go down to the 'next' level. Any of the locations however, on any level should be able to be 'added' so I'm either going to have an accessory button, or just a custom button that says add on the cell.

I want to do this using delegates but I'm not quite sure where the delegate should be. I can think of 2 options:
1. Subclass UINavigationController to a LocationNavigationController with a LocationNavigationControllerDelegate but then I need to find someway to message back down with my LocationListTableView
2. Make a LocationListTableView that holds a delegate, and everytime I go to the 'next' level down, just keep passing the delegate along. So when they finally hit the 'add' button the cell, my original ViewController can get the location and dismiss it. It does seem wrong though passing the Delegate all the way up the chain of TableViews. In this method I would just create a new NavController first, then pop on the root tree of the LocationListTableView

+1  A: 

Have a look at the View Controller Programing Guide, specifically, the section on dismissing a modal controller.

Their code example is using a modal screen to add a recipe to a table view controller which presented it.

Ben S
So you're saying I sohuld just continually push up the delegate to each of the TableViews, and if one decides to act, it'll go?
aleclerc
The UITableViewControllers _are_ the delgates. The modal view lets the UITableViewControllers know when they're done using your protocol to pass the info, who in turn, dismisses them and uses the passed info to add the new row.
Ben S
Alright, I get what you are saying, however I don't completely agree. The UITableViewController should have a reference TO a delegate, they themselves are not the delegate. The original ViewController where i call presentModalView is the delegate. And when my UITableView does something, it calls the delegate and says 'Hey I'm done'. So this is why I was asking if I pass the delegate reference through the TableView, and then when one decides to act it calls the delegate, or if there was some other way I should be handling that.
aleclerc