gpt4 book ai didi

ios - Swift 在 indexPath 中使用 prepareForSegue

转载 作者:搜寻专家 更新时间:2023-11-01 05:46:09 24 4
gpt4 key购买 nike

我有一个模型类和两个 tableView Controller 。整数值中的此类。此类中的值使用 prepareforsegue 方法发送给其他类。但我无法准备获取 tableView 索引路径。我做错了吗?

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

let subCategory: SubCategoryVC = segue.destinationViewController as SubCategoryVC

let indexPath = self.categoryTableView.indexPathForSelectedRow()

model = arrList[indexPath?.row] **//incorrect line**

subCategory.getCatID = model.categoryID
}

最佳答案

indexPath?.row 返回可选值。您不能在数组子脚本中使用它。你必须先 uwrap 它。这是示例:

if let indexPath = categoryTableView.indexPathForSelectedRow() {
// do the work here
}

关于ios - Swift 在 indexPath 中使用 prepareForSegue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27819853/

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