Could not cast value of type 'UINavigationController'

后端 未结 3 907
无人及你
无人及你 2021-02-01 06:45

I am implementing a search interface for my application, so basically I will pass the search keyword from one ViewController to another ViewController.

I have done this

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 07:07

    Based on Semih's answer, you can also do this to pass a variable to next segue if you don't want to use an identifier:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let nav = segue.destination as? UINavigationController, 
            let vc = nav.topViewController as? TestViewController {
            vc.username = "Test"
        }
    }
    

提交回复
热议问题