gpt4 book ai didi

iphone - 未调用 UIViewController 准备 segue 方法

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

我正在尝试将数据从 tableview 单元格传递到选项卡 View Controller ,以供选项卡 View Controller 的相应 View 使用。但是下面的重写 func prepare 方法没有被调用,程序完全绕过这个方法转到选项卡 View Controller 。

Storyboard showing the views

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let selectedCarIndex = self.savedCarsTableVC.indexPathForSelectedRow?.row

let destVC = segue.destination as! TabBarController
destVC.selectedCar = savedCars[selectedCarIndex!]
}

我期待 selectedCar 对象从数组返回数据,但它是 nil

最佳答案

我会尝试在 tableView didSelectRow 方法中设置 selectedCarIndex。此外,请确保您要导航到 TabBarController,而不是 TabBar 中嵌入的某些 ViewController。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {
self.performSegue(withIdentifier: "youridentifier", sender: indexPath)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let selectedCarIndex = sender as! IndexPath

let destVC = segue.destination as! TabBarController //Are you sure this is the correct ViewController to be casting to?
destVC.selectedCar = savedCars[selectedCarIndex.row]
}

关于iphone - 未调用 UIViewController 准备 segue 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43399120/

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