override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "naarPersoonView"
{
let tabCtrl = segue.destination as! UITabBarController
let vc = tabCtrl.viewControllers![0] as! PersoonViewController
let indexPath = self.tableView.indexPathForSelectedRow
vc.persoon = personen[(indexPath?.row)!]
}
}
当我尝试将一个人从我的TableViewController发送到我的persoonViewController(Tab视图控制器)时,它给了我这个错误
Could not cast value of type 'UIViewController' (0x10ff68758) to 'DriesVD.PersoonViewController' (0x10e312750).
答案 0 :(得分:0)
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "naarPersoonView"
{
let tabCtrl = segue.destination as! UITabBarController
let desView: PersoonViewController = tabCtrl.viewControllers?.first as! PersoonViewController
let indexPath = self.tableView.indexPathForSelectedRow
desView.persoon = personen[(indexPath?.row)!]
}
}
我通过上面的例子解决了我的问题,感谢您的所有快速回复