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

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

问题描述:

Xcode6 在创建新项目时删除了空应用程序模板。我们如何在 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 而且更早。但是我们仍然可以通过以下步骤在 XCode6 中创建不带 Storyboard 的应用程序:

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


  1. 使用 XCode6创建单一视图应用程序

  2. 删除 Main.storyboard LaunchScreen.xib (选择它们,右键单击,然后选择
    从项目中删除它们,或者完全删除它们。)

  3. 删除主故事板文件基本名称和启动屏幕界面
    文件基名 Info.plist 文件中的条目。

  4. 打开AppDelegate.m,编辑applicationDidFinishLaunchingWithOptions,使其如下所示:

  1. Create an Single View Application with XCode6
  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:

- (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;
}

对于Swift 2.x:

For 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
}

对于Swift 3:

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
}