我有这个警告: 不建议在独立的视图控制器上显示视图控制器
我需要知道如何在另一个VC中设置rootViewController并避免出现此警告
我的VC中有以下代码:
@IBAction func dissmissInfo(_ sender: UIButton) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "firstVC")
present(vc, animated: true, completion: nil)
})
在第一个VC中,我有这个:
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.keyWindow?.rootViewController = self
}
但是当我尝试移动到另一个VC时,我有相同的警告: 不建议在独立的视图控制器上显示视图控制器
答案 0 :(得分:1)
您的意思是您想要设置firstVC
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "firstVC")
作为新的RootViewController吗?
如果是:
@IBAction func dissmissInfo(_ sender: UIButton) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "firstVC")
UIApplication.shared.keyWindow?.rootViewController = vc
})
然后在firstVC中删除
UIApplication.shared.keyWindow?.rootViewController = self