[英]Use of unresolved identifier 'LaunchScreenViewController'
I have one issues, i want to restart my app, and i have only one solution how to do it. 我有一个问题,我想重新启动我的应用程序,而我只有一个解决方案。
It's only pop to rootViewController. 仅弹出到rootViewController。
My code: 我的代码:
func restartApplication() {
let viewController = LaunchScreenViewController()
let navCtrl = UINavigationController(rootViewController: viewController)
guard
let window = UIApplication.shared.keyWindow,
let rootViewController = window.rootViewController
else {
return
}
navCtrl.view.frame = rootViewController.view.frame
navCtrl.view.layoutIfNeeded()
UIView.transition(with: window, duration: 0.3, options: .transitionCrossDissolve, animations: {
window.rootViewController = navCtrl
})
}
But i get this error: 但是我得到这个错误:
Use of unresolved identifier 'LaunchScreenViewController'
使用未解析的标识符“ LaunchScreenViewController”
What is the problem? 问题是什么?
For xif Just replace the line of code with this .. 对于xif,只需用此..替换代码行。
let viewController = LaunchScreenViewController(nibName: "LaunchScreenViewController", bundle: nil)
Instead of this one .. 代替这个..
let viewController = LaunchScreenViewController()
For Storyboard 对于情节提要
// global declaration
let kApplicationDelegate = UIApplication.shared.delegate as! AppDelegate
// use this extension
extension UIViewController{
func changeStoryboardTo(){
let nav = UINavigationController(rootViewController: self)
UIView.transition(with: (kApplicationDelegate.window)!,
duration:0.5,
options:UIViewAnimationOptions.transitionFlipFromLeft,
animations: {
kApplicationDelegate.window?.rootViewController = nav
// do something
}, completion:{
finished in
// competion code
})*/
}
}
extension UIStoryboard{
func getControllerInstance(storyBoardName : String, identifire : String) -> UIViewController {
let objStoryBoard = UIStoryboard(name: storyBoardName, bundle: Bundle.main)
let vc = objStoryBoard.instantiateViewController(withIdentifier: identifire)
return vc
}
}
Calling 呼唤
_ = UIStoryboard().getControllerInstance(storyBoardName: "yourStoryboardName", identifire: "yourViewControllerIdentifire").changeStoryboardTo()
如果您正在使用情节提要,并且已经为特定的ViewController设置了ViewController标识符
let viewController = UIStoryboard(name: "LaunchScreenStoryboard", bundle: nil).instantiateViewControllerWith(identifier: "LaunchScreenViewController") as! LaunchScreenViewController
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.