ios - 在 AppDelegate 中推送时不显示新的 ViewController
问题描述
这是我在 swift 5 中从应用程序委托中呈现 ViewController 的代码,我已经完成了与everyOne 相同的所有操作,但是在启动应用程序时不会显示新的 ViewController。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let welcome = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = welcome
self.window?.makeKeyAndVisible()
return true
}
解决方案
把它放进去
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let welcome = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = welcome
self.window?.makeKeyAndVisible()
return true
}
更新: 如果它不工作尝试:
if let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main){
if let welcome = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen{
//Does it come here?
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = welcome
self.window?.makeKeyAndVisible()
}
}
确保你真正进入身体,如果最内在if
的是if let welcome = mainStoryboardIpad.instantiateViewController(withIdentifier: "Welcome") as! WelcomeScreen
推荐阅读
- python-3.x - 错误:IndexError:列表索引超出范围
- java - 如何根据 ListView 中的字符串值设置TextColor?
- c# - Xamarin Forms 项目中的错误 CS0433
- stackdriver - 有没有办法在 Stackdriver Logs Viewer 中查看周围的日志?
- matlab - 在 y 轴上旋转角度 theta 以欧拉角定向的关节
- javascript - 从目录路径获取对象数组中的目录路径作为字符串
- python - 测试 Google Street View Publish API 时出现“pkg_resources.DistributionNotFound: google-gax”
- c - 从函数返回的 char* 数组打印不正确的值(可能是内存管理)
- vba - 实现与二进制兼容性
- delphi - 带有MultiSelect的Firemonkey(Delphi)TListbox获取所选项目