Adding new Viewcontroller's view as subview

后端 未结 1 352
轻奢々
轻奢々 2021-01-19 07:42

I am trying with the following and failed to add new viewcontrollers view. Is it only way to present view controller ? Cant we add view from other storyboard viewcontrollers

相关标签:
1条回答
  • 2021-01-19 08:23

    You need to also add CustomViewController as ChildViewController in your current Controller.

    let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController
    vc.view.frame = self.view.bounds
    self.addChildViewController(vc)
    self.view.addSubview(vc.view)
    vc.didMove(toParentViewController: self) //OR  vc.willMove(toParentViewController: self)
    
    0 讨论(0)
提交回复
热议问题