'Application windows are expected to have a root view controller at the end of application launch' [

来源:互联网 发布:淘宝400电话申请 编辑:程序博客网 时间:2024/05/22 11:31

删除Main.storyboard和launchboard.storyboard之后,将General ——》Deployment Info ——》Main Interface设置为空

在didFinishLaunchingWithOptions中添加以下代码后启动模拟器出现'Application windows are expected to have a root view controller at the end of application launch'异常


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {      // Override point for customization after application launch.        self.window = UIWindow(frame: UIScreen.mainScreen().bounds);      self.window?.backgroundColor = UIColor.redColor();      self.window?.makeKeyAndVisible(); 

解决办法是:


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {      // Override point for customization after application launch.        self.window = UIWindow(frame: UIScreen.mainScreen().bounds);      self.window?.backgroundColor = UIColor.redColor();      self.window?.makeKeyAndVisible();      let rootViewController = UIViewController() as UIViewController;      let navigationController = UINavigationController(rootViewController: rootViewController) as UINavigationController;      self.window?.rootViewController = rootViewController;      self.window?.addSubview(navigationController.view);      return true  }  


阅读全文
0 0