Reputation: 8002
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:
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
Edit(s) / answers to comment questions:
prepare
unlike clicking a table cellUpvotes: 0
Views: 198
Reputation: 535168
The problem is that you have accidentally disabled user interaction for the table view. (I knew this was the problem the moment I ran the project and discovered that I couldn't scroll the table view or click any of the stars to change the rating.)
Look at the bottom of this screen shot. You need to make sure that User Interaction Enabled is checked as in the screen shot. In your project, it is not. Hence the whole table is "untouchable."
Upvotes: 1