I’m sorry if this duplicates other threads. I’ve pored through about a dozen, over several hours, but none seem to quite apply to my situation. Namely;
- A button presents a popover
- The popover contains a table view, nested inside a navigation controller
- The user navigates to the second level of the nav controller (a second tableViewController), then makes a selection
- Upon making the selection, the popover should dismiss, and pass back the indexPath.row to the original screen.
Importantly, I’m using storyboards and segues to do this (this may be part of the problem!)
I’ve tried implementing custom delegate methods to do this, but I’m getting hopelessly tangled up. Mainly because
a) The actual delegate is two levels away, and I’m having trouble conveying this “up the chain”, as it were.
b) The [segue destinationViewController] is the navigationController. I’m not sure how to get a hook into the actual tableViews it contains, to retrieve or set properties (such as the delegate)
Does this make any sense to anyone? Reading back, this question is almost as bamboozled as I am. If you can decipher it, and have any advice, I’d be very grateful.
You can get to the actual view controller (which has your table view) using the viewControllers property of your navigation controller (
segue.destinationViewController). Once you have a pointer to this view controller, set its delegate. Then intableView:didSelectRowAtIndexPath, notify the delegate that something was selected, and the delegate can dismiss the popover.EDIT: This could be in your prepareForSegue:
Apple docs about the
viewControllersproperty of a UINavigationController:When using a segue, the root view controller is the only view controller, so lastObject always returns the root view controller.
Now, keep in mind that when you select a species in SpeciesTableViewController, you’re triggering a segue, and will have to set the delegate of SpeciesDetailViewController. In SpeciesDetailViewController’s
didSelectRowForIndexPathyou can send a message to the delegate to dismiss the popover.