Swift pass data through navigation controller

后端 未结 8 2119
青春惊慌失措
青春惊慌失措 2020-12-12 18:13

One of my segues transitions from a view controller to a tableview controller. I want to pass an array between the two, but with a navigation controller before the tableview

8条回答
  •  情歌与酒
    2020-12-12 18:19

    Swift 5

    class MyNavigationController: UINavigationController {
        
        var myData: String!
        
        override func viewDidLoad() {
            if let vc = self.topViewController as? MyViewcontoller{
                vc.data = self.myData
            }
        }
        
    }
    
    
       let navigation = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MyNavigationController") as! MyNavigationController
       navigation.myData = "Data that you want to pass"
       present(navigation, animated: true, completion: nil)
    

提交回复
热议问题