gpt4 book ai didi

swift - 节中选定行的索引

转载 作者:行者123 更新时间:2023-11-28 14:41:12 24 4
gpt4 key购买 nike

我有一个按部分分隔的食品项目,我希望能够按下食品项目并转到食品项目详细信息页面。我的问题是我无法将信息传递给详细信息,因为我没有获得该部分中项目的索引。FoodItem 来自 coredata。

 var allFoodItems = [[FoodItem]]()
var foodItemTypes = [
FoodItemType.Appetizer.rawValue,
FoodItemType.SoupSalad.rawValue,
FoodItemType.Main.rawValue]

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

let foodItem = FoodItem()
guard let section = foodItemTypes.index(of: foodItem.type!) else { return }

let row = allFoodItems[section].count

let selectedIndexPath = IndexPath(row: row, section: section)

let foodItemDetailController = FoodItemDetailController()
foodItemDetailController.foodItem = selectedIndexPath
navigationController?.pushViewController(foodItemDetailController, animated: true)
}

enter image description here

最佳答案

直接发送indexPath即可

 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

let foodItemDetailController = FoodItemDetailController()

foodItemDetailController.foodItem = indexPath // if IndexPath is the type

navigationController?.pushViewController(foodItemDetailController, animated: true)
}

//

或者发送点击的项目

 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

let all = allFoodItems[indexPath.section]

let item = all[indexPath.row]

let foodItemDetailController = FoodItemDetailController()

foodItemDetailController.foodItem = item // if foodItem is the type

navigationController?.pushViewController(foodItemDetailController, animated: true)
}

关于swift - 节中选定行的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50514933/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com