#StackBounty: #ios #swift #xcode #segue Manual (automatic) Segue not working – table view cell

Bounty: 400

I’m new to Xcode and I’m following the tutorial here which goes through how to add a manual segue.

https://github.com/AdditionAddict/learnXcode

Problem: When clicking on a table cell in the simulator the manual segue is not triggered.

What I’ve tried: I’ve added a manual (automatic) segue, an identifier, and whilst the tutorial says as this point a selection of a cell with result in going from the table view cell to the meal detail scene, I’ve continued to the code part and my breakpoint in prepare still does not trigger.

    // MARK: - Navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        super.prepare(for: segue, sender: sender)
        
        switch(segue.identifier ?? "") {
            
        case "AddItem":
            os_log("Adding a new meal", log: OSLog.default, type: .debug)
            
        case "ShowDetail":
            // set the meal for the `MealViewController` as the meal selected in the `MealTableViewController`
            os_log("Show detail of a meal", log: OSLog.default, type: .debug)
            
            guard let mealDetailViewController = segue.destination as? MealViewController else {
                fatalError("Unexpected destination, (segue.destination)")
            }
            guard let selectedMealCell = sender as? MealTableViewCell else {
                fatalError("Unexpected sender, (String(describing: sender))")
            }
            guard let indexPath = tableView.indexPath(for: selectedMealCell) else {
                fatalError("The selected cell is not being displayed by the table")
            }
            
            let selectedMeal = meals[indexPath.row]
            mealDetailViewController.meal = selectedMeal
            
        default:
            fatalError("Unexpected Segue Identifier")
        }
    }

Checks made:
If, for the purposes of debugging only, I put the following in my MealTableViewController.swift with a breakpoint nothing happens when I click a table cell:

    override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
        return true
    }

This makes me think the table cells aren’t registering a ‘selection’.

Table View Selection property is Single Selection.

The custom MealTableViewCell has User Interaction Enabled checked.

Clicking the MealTableViewCell in the outline pane and selecting the Connections inspector in the utilities pane also shows the segue:

Connections Inspector showing segue

Final bits: Is it still possible to add a manual (automatic) segue?
Tutorial is in archive and I’ve managed to follow most of it with small changes.
Using Xcode 11.6

main.storyboard and Identity Inspector

Edit(s) / answers to comment questions:

  1. added (automatic) to manual. I mean the method the tutorial uses from table cell to meal detail.
  2. There isn’t anything in front of the table (that I’m aware of) such as a tap gesture recogniser
  3. The Plus segue works and triggers the prepare unlike clicking a table cell


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.