Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to present a viewcontroller embedded in a navigation caontroller by tapping a button. Everytime I tap the button the app crashes saying Could not cast value of type 'UINavigationController' (0x11320f420) to

my code to display the Viewcontroller

@IBAction func skipButtonTapped(_ : UIButton) {
    let viewController: CategoryVC = UIStoryboard(name: "CategorySB", bundle: nil).instantiateViewController(withIdentifier: Constants.CATEGORY_VC) as! CategoryVC
    self.present(viewController, animated: true, completion: nil)
}

any help thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
138 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can try

let nav = UIStoryboard(name: "CategorySB", bundle: nil).instantiateViewController(withIdentifier: Constants.CATEGORY_VC) as! UINavigationController 
self.present(nav, animated: true, completion: nil)

//

if you wan to access root

if let cat = nav.topViewController as? CategoryVC {

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...