swift: select dynamic table cell and either push or pop view controller depending on stack

295 views Asked by At

I've got a list in a dynamic table controller, embedded in a navigation controller and a tab controller (using storyboard). On selecting a cell from the list, I would like to either:

  1. push, with prepareForSegue gathering data across to the new view controller, or...
  2. pop, using delegation for data transfer, if I've arrived at the dynamic table controller by segue from another tabbed/navigated controller.

At the moment I've got standard code for protocol/delegate/didSelectRowAtIndexPath (pop) with override prepareForSegue (push).

Everything's fine if I'm pushing, but when I expect to pop, the result is a quick push, immediately followed by an automatic pop, back to the list.

I'd prefer not to add an accessory to the dynamic table cell for the push, but perhaps that's the only way? Any suggestions?

1

There are 1 answers

0
Bannings On BEST ANSWER

Consider the shouldPerformSegueWithIdentifier method:

override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool {
    if /* you determine this */ {
        self.navigationController?.popViewControllerAnimated(true)

        return false
    } else {
        return true
    }
}