- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建一个应用程序,其中显示膳食列表,当您单击其中一个时,它会显示该膳食的更多详细信息。
当我运行它时,它会在 table 上显示餐食,但是当我单击餐食时,它只会提供餐食模板,
这是我用于 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)")
}
}
在代码中,guard 语句应该导致它在 ViewController 中显示项目数据,但我在底部收到默认错误
最佳答案
您可以在 didSelectRowAt
上访问膳食对象,例如,您有一组膳食来生成单元格,但只有一个部分
var meals: [Meal]
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return meals.count
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedMeal = meals[indexPath.row]
let mealDetailsVC = MealDetailsViewController()
mealDetailsVC.meal = selectedMeal
navigationController?.pushViewController(mealDetailsVC, animated: true)
}
关于ios - Xcode TableViewCell 推送到 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43153272/
[将数据从一个 TableViewCell 传输到另一个 TableViewCell][1] 我有 CountriesViewController 和 tableView ,其中是不同国家/地区的列表
我的 TableView 里面有 3 个 TableViewCell。 第一个 TableViewCell 有:标签 第二个 TableViewCell 有:TextField 第三个 TableVi
我不确定这是否是一个奇怪的设置,但我有两个自定义 tableView 单元格 - 手机手机 电子邮箱 在 PhoneCell 中,我有两个文本字段,这些文本字段中有一些值。在 EmailCell 中,
所以我有一个 ExpyTableView 类型的 mainTableView ( https://github.com/okhanokbay/ExpyTableView )。一切都很好,我设法实现了它
据我了解,我无法使用 socket 连接将单元格中的按钮连接到我的 TableViewController。 不过,我可以使用操作连接将单元格中的按钮连接到我的 TableView。这是我巨大问题的根
我想在动态 UITableViewCell 中添加一个动态 UICollectionView,当 CollectionView 接收并准备 contentView 时,它会自动更新其高度。有什么好的方
I want different images under different heading //ViewController.swift var categories = ["Good Aft
我有以下表格 View : 当用户点击蓝色的 Pay Cash/Card 按钮时,他们会转到另一个 tableView。 我遇到的问题是;当用户单击按钮时,不会在委托(delegate)方法中捕获 t
我有一个带有自定义单元格的 TableView。单元格中的 subview 之一是 UIButton。当用户单击按钮时,我希望背景发生变化。我得到了所有的工作。但问题是,直到我将受影响的单元格滚动出屏
- (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerNib:[UINib nibWithNibName
我今天花了六个多小时研究并尝试创建动态单元,但没有成功。我也找到了一些很棒的教程。我做错了什么,希望有人能告诉我什么。 我的应用: table 开始是空的。单击添加按钮会显示一个模态 VC,其中有两个
请注意此代码。 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITa
我有一个 tableViewCell,总共包含 8 个图像,分为两个 block (每个 block 4 个图像)。这些图像会异步下载并存储到数组中,然后在 tableViewCell 的 cellF
运行我的弹出窗口时,代码显示在左上角,而不是显示在单击图标的同一位置,是否可以更改某些内容来纠正位置? 最佳答案 这是因为您已将 aView 的 CGRect 设置为 x 和 y 为 0。 如果您以编
我用 CustomTableViewCells 制作了一个应用程序。我在 MainStoryBoard 上设置了一个 UIButton。 我想在点击时更改按钮的图像。当我再次点击时,我希望按钮返回到原
我正在编写一个 iOS 应用程序。用户输入电影搜索关键字,它会从 omdbapi.com 获取数据并在表格 View 中显示电影。问题是该 TableView 单元格未正确显示。 项目网址: proj
我目前有一个表格 View ,其中加载的单元格中有一个 uicollectionview。我目前遇到了表格 View 单元格的两个问题。 1) TableView 中的第一个单元格应该具有紫色背景,但
我有一个 TableView,可以在其中加载自定义单元格。在自定义单元格中,有一个文本字段,当表格 View 填充自身时,该文本字段会加载自定义拨号盘并自行关闭。这个 float 数字键盘在初始化期间
这是我的主屏幕当单击单元格突出显示时,描述将转到下一个 View Controller ,并且单元格会突出显示,当我单击未突出显示的单元格时,因此单元格未突出显示,这意味着只有零索引单元格突出显示,没
我想以编程方式将两个文本字段添加到 tableViewCell 子类(稍后会详细介绍),但很难从 View Controller 访问文本字段。 我的 TableView 子类是: - (id)ini
我是一名优秀的程序员,十分优秀!