如何在 Swift 中显示 VC 并设置为新根 viewController?
How can I present VC and set as new Root viewController in Swift?
我有这个警告:
不鼓励在分离的视图控制器上呈现视图控制器
我需要知道如何在另一个 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 时,我收到了相同的警告:
不鼓励在分离的视图控制器上呈现视图控制器
你的意思是你要先设置VC
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
我有这个警告: 不鼓励在分离的视图控制器上呈现视图控制器
我需要知道如何在另一个 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 时,我收到了相同的警告: 不鼓励在分离的视图控制器上呈现视图控制器
你的意思是你要先设置VC
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