如何在没有 Storyboard 的情况下在 Xcode 中创建一个空应用程序

如何在没有 Storyboard 的情况下在 Xcode 中创建一个空应用程序

问题描述:

Xcode6 在创建新项目时删除了 Empty Application 模板.我们如何在 Xcode6 及更高版本中创建一个空的应用程序(没有 Storyboard),就像在早期版本中一样?

Xcode6 has removed the Empty Application template when creating a new project. How can we create an empty application (without Storyboard) in Xcode6 and above, like in earlier versions?

XCode6 及以上版本没有选项可以像 XCode5 和早些时候.但是我们仍然可以通过以下步骤创建没有 Storyboard 的应用程序:

There is no option in XCode6 and above versions for directly creating an Empty Application as in XCode5 and earlier. But still we can create an application without Storyboard by following these steps:

  1. 创建一个单视图应用.
  2. 删除 Main.storyboardLaunchScreen.xib(选择它们,右键单击,然后选择从项目中删除它们,或完全删除它们).
  3. 删除主故事板文件基本名称"和启动屏幕界面"文件库名称"Info.plist 文件中的条目.
  4. 打开 AppDelegate.m,然后编辑 applicationDidFinishLaunchingWithOptions,使其看起来像这样:
  1. Create a Single View Application.
  2. Remove Main.storyboard and LaunchScreen.xib (select them, right-click, and choose to either remove them from the project, or delete them completely).
  3. Remove "Main storyboard file base name" and "Launch screen interface file base name" entries in Info.plist file.
  4. Open AppDelegate.m, and edit applicationDidFinishLaunchingWithOptions so that it looks like this:

Swift 3 及更高版本:

Swift 3 and above:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool 
    {
        self.window = UIWindow(frame: UIScreen.main.bounds)
        self.window?.backgroundColor = UIColor.white
        self.window?.makeKeyAndVisible()
        return true
    }

Swift 2.x:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool 
    {
        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
        self.window?.backgroundColor = UIColor.whiteColor()
        self.window?.makeKeyAndVisible()
        return true
    }

目标-C:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.rootViewController = [[ViewController alloc] init];
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }