新建swift APP后, 设置rootviewcontroller 为其他Controller,如果 勾选的是main.storyboard 运行app ,删除后main.storyboard会有黑屏问题。
1.检查info.plist 文件
首先我们去到info.plist,删掉如下图箭头所示

2.删除SceneDelegate.swift 文件
3.删除APPdelegate.swift 中 与Scene相关的代码

4.在APPdelegate.swift里面添加window属性
-
class AppDelegate: UIResponder, UIApplicationDelegate { -
var window: UIWindow? -
/** -
*入口区,调用区 -
*/ -
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { -
window = UIWindow(frame: UIScreen.main.bounds) -
window?.rootViewController = vc -
window?.makeKeyAndVisible() -
return true -
} -
}
当新建的Swift APP不再使用main.storyboard作为启动界面时,可能会遇到黑屏问题。解决方法包括:检查并删除info.plist中与storyboard相关的配置,移除SceneDelegate.swift文件,从APPdelegate.swift中删除Scene相关的代码,并在APPdelegate中设置自定义的rootViewController。通过这些步骤可以确保APP正确启动并显示指定的控制器。
760

被折叠的 条评论
为什么被折叠?



