我尝试使用以下方法添加新的视图控制器视图,但失败了。这是唯一的呈现视图控制器的方式吗?不能从其他故事板的视图控制器视图中添加视图吗?
//Working
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController
self.present( viewcontroller , animated: true, completion: nil)
//Not working
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "customView") as! CustomViewController
vc.view.frame = self.view.frame
self.view.addSubview(vc.view)
vc.customview
还没有加载,所以可能会返回 nil。你可以简单地尝试一下来检查它。 - Nirav D