gpt4 book ai didi

ios - App Delegate 中用于加载 Storyboard的 Swift 代码导致崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 06:46:23 26 4
gpt4 key购买 nike

我有一个正在编写的通用应用程序,我最初使用两个 Storyboard文件编写它。我在 App Delegate didFinishLaunchingWithOptions 例程中有代码来决定要加载哪个 Storyboard 并离开它。从那以后我意识到这是一件愚蠢的事情,因为我有重复的代码,所以我删除了一个 Storyboard并使另一个通用。我已经修复了 VC 以指向正确的类和所有内容。但是,我的应用程序现在拒绝启动。当我在 sim 中运行它时,它给了我错误

The app delegate must implement the window property if it wants to use a main storyboard file.

.

这是我在 App Delegate 中的代码:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.

var deviceIdiom = UIDevice.currentDevice().userInterfaceIdiom
if deviceIdiom == UIUserInterfaceIdiom.Phone {
strDevice = "iPhone"
} else if deviceIdiom == UIUserInterfaceIdiom.Pad {
strDevice = "iPad"
} else {
strDevice = "Unknown"
}

return true
}

我做错了什么?

(我已经看过但没有帮助的问题): Unique Issue displaying first storyboard scene in Xcode
The app delegate must implement the window property if it wants to use a main storyboard file
Managing two storyboards in App Delegate
How to manually set which storyboard view to show in app delegate
Swift - Load storyboard programatically

最佳答案

您的应用委托(delegate)需要像这样开始:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

//...
}

关于ios - App Delegate 中用于加载 Storyboard的 Swift 代码导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30317162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com