Error: Could not cast value of type 'UINavigationController'

前端 未结 1 1212
日久生厌
日久生厌 2021-01-29 08:13

I want to present a view controller in FavouriteButtonHandler on a button press.

When I press the button, I get the following error:

Could not cast value o

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-29 08:38

    It's working perfectly for me :

    Pushing the PDFViewController into Navigation Stack :

       if let presentVC = self.storyboard?.instantiateViewController(withIdentifier: "PDFViewController") as? PDFViewController{
            self.navigationController?.pushViewController(presentVC, animated: true)
        }
    

    OR

        if let presentVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PDFViewController") as? PDFViewController {
            self.navigationController?.pushViewController(presentVC, animated: true)
        }
    

    Please, make sure that your current viewController should belong to the top of Navigation stack before pushing anything on it.

    0 讨论(0)
提交回复
热议问题