App代理中的Swift代码加载故事板导致崩溃

时间:2015-05-19 05:07:19

标签: ios swift appdelegate xcode-storyboard

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

  

如果想要使用主故事板文件,则app委托必须实现window属性。

以下是我在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

1 个答案:

答案 0 :(得分:3)

您的应用代表需要像这样开始:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  //...
}
相关问题