1
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)!]
    }
}

When i try to send a person from my TableViewController to my persoonViewController( Tab view Controller ) it gave me this error Could not cast value of type 'UIViewController' (0x10ff68758) to 'DriesVD.PersoonViewController' (0x10e312750).

Khushbu
  • 2,342
  • 15
  • 18
DriesVD
  • 11
  • 4
  • what type of personen array & persoon var ?? – Shehata Gamal May 14 '18 at 11:49
  • i made a class Persoon and in this controller I made a var persoon wich is from type Persoon and a personen array where i've put my objects of Persoon in – DriesVD May 14 '18 at 12:03
  • Please refer this link: https://stackoverflow.com/questions/27296742/pass-data-from-tableview-to-tab-bar-view-controller-in-swift – Khushbu May 14 '18 at 12:08
  • What type is `PersoonViewController`? Is it a subclass of `UIViewController`? – Daven May 14 '18 at 18:33
  • No from UITabBarController – DriesVD May 14 '18 at 18:36
  • How are you setting the `ViewControllers` of your `tabCtrl`? When you are accessing your `tabCtrl.viewControllers![0]`, it is receiving a subclass of `UIViewController`. This is not the same as a `UITabBarController` (which `PersoonViewController` is a subclass of), so it is throwing this error. – Daven May 14 '18 at 18:52
  • Yeah thank you I solved it – DriesVD May 14 '18 at 20:00

1 Answers1

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)!]
    }
}

I solved my problem with the example above thanks for all your quick responses

DriesVD
  • 11
  • 4