Search code examples
iosuitableviewswiftsegueuicontainerview

iOS - Can I trigger a segue based on tap in container view?


I have a UITableViewController called ListViewController set up (well it is actually a Parse.com PFQueryTableViewController, but that is by-the-by) and at the top of the UITableView I have a Container View which has a UITableViewController embedded within it.

The embedded UITableViewController has a couple of static cells in it. What I would like to do, is to trigger a segue from from the ListViewController to another view (Navigation Push) when the user taps on one of the cells within the embedded UITableViewController.

I have seen other questions about passing information from view to view, but this is specifically for how I might go about triggering a segue.

NOTE: I am developing the app in Swift


Solution

  • You should set up a delegate relationship between the embedded table view controller and your ListViewController so that when the embedded table cells are tapped the delegate callback is fired. The callback handler (part of ListViewController) can then trigger the segue.

    So the embedded table view controller has a delegate property that can be set, and ListViewController implements the delegate protocol.