0
我正在创建一个应用程序,在其中显示餐桌列表,并且当您单击其中一个时,它会更详细地显示膳食。Xcode TableViewCell推送到ViewController
当我运行它,它会显示在桌子上吃饭,但是当我点击了一顿它只是提供了一顿模板,
这里是我使用的代码为我TableViewController显示项目
private func loadSampleMeals() {
let photo1 = UIImage(named: "Sprite")
let photo2 = UIImage(named: "HotCheetos")
let photo3 = UIImage(named: "Nachos")
guard let meal1 = Meal(name: "Sprite", price: "$1.50", photo: photo1, rating: 0, calories: "Calories: 129", description: "Description: A refreshing lemon-lime soda") else {
fatalError("Unable to instantiate meal1")
}
guard let meal2 = Meal(name: "Hot Cheetos", price: "$1.50", photo: photo2, rating: 0, calories: "Calories: 160", description: "Description: A spicy version of original cheetos") else {
fatalError("Unable to instantiate meal2")
}
guard let meal3 = Meal(name: "Nachos", price: "$1.50", photo: photo3, rating: 0, calories: "Calories: 436", description: "Description: Tortilla chips with a side of smooth nacho cheese") else {
fatalError("Unable to instantiate meal2")
}
meals += [meal1, meal2, meal3]
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
switch(segue.identifier ?? "") {
case "ShowDetail":
guard let mealDetailViewController = segue.destination as? MealViewController else {
fatalError("Unexpected destination: \(segue.destination)")
}
guard let selectedMealCell = sender as? MealTableViewCell else {
fatalError("Unexpected sender: \(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; \(segue.identifier)")
}
}
在代码中,保护报表应使其显示在视图控制器的项目数据,但我得到了默认的错误在底部
您是否通过数据,而改变tableview控制器到详细控制器? –
你可以用你的tableView方法显示一些代码,它会告诉我们你正在做什么 –
删除顶部导航控制器...在应用程序中应该只有1个导航控制器... –