Can't cast value of type UIViewController to PatternDetailViewController

前端 未结 8 1620
孤街浪徒
孤街浪徒 2020-12-06 04:29

Am trying to downcast a view controller to a detail view controller but can\'t. Am using Core Data (for the first time). The error is in the prepareForSegue method and reads

8条回答
  •  一生所求
    2020-12-06 04:51

    It looks like you are using a navigation controller judging by your viewDidLoad() in PatternDetailViewController.

    If PatternDetailViewController is embedded in a UINavigatonController then the navigation controller will be segue.destinationViewController.

    Get the PatternDetailViewController like this:

    let vc: UINavigationController = segue.destinationViewController as! UINavigationController
    let detailVC = vc.topViewController as! PatternDetailViewController
    detailVC.pattern = self.selectedPattern
    

提交回复
热议问题