Can't cast value of type UIViewController to PatternDetailViewController

前端 未结 8 1616
孤街浪徒
孤街浪徒 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:56

    The problem, as you have said, is in these lines:

    if segue.identifier == "patternDetailSegue" {
        var detailViewController = segue.destinationViewController as! PatternDetailViewController 
        // Could not cast value of type 'UIViewController' to 'Patternz.PatternDetailViewController'
    

    The error message tells you that the destinationViewController of this segue is not, in fact, a PatternDetailViewController. You may think it is, but it isn't. You need to examine this segue in the storyboard and see what's really at the destination end of it.

    The fact that the error message describes it as a UIViewController makes me suspect that you forgot to enter any view controller type in this view controller's Identity inspector in the storyboard:

    Xcode Screenshot

提交回复
热议问题