I know how to transfer information from a TableViewController to a ViewController, but now I need to switch to another TableViewController using the function prepare(for segue: UIStoryboardSegue, sender: Any?)
, plus I think you need to modify the value that returns tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
depending on how many cells each table has is it like that?
That is, each cell will direct you a different TableViewController and that other TableViewController will have a different number of cells than the rest.
I leave my code of how I pass information from a TableViewController to a ViewController so that you can help me with the changes that I have to make, thank you community. :)
var recipes : [Recipe] = []
override func viewDidLoad() {
super.viewDidLoad()
var recipe = Recipe(name: "Tortilla de patatas",
ingredients: ["Patatas", "Huevos", "Cebolla"])
recipes.append(recipe)
recipe = Recipe(name: "Pizza margarita",
ingredients: ["Harina", "Levadura", "Aceite", "Sal", "Salsa de Tomate", "Queso"])
recipes.append(recipe)
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.recipes.count
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showRecipeDetail" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let selectedRecipe = self.recipes[indexPath.row]
let destinationViewController = segue.destination as! DetailViewController
destinationViewController.recipe = selectedRecipe
}
}
}