Xcode 4.2 iOS 空应用程序和故事板

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7906541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:04:31  来源:igfitidea点击:

Xcode 4.2 iOS Empty Application and storyboards

iosxcodeios5storyboardxcode4.2

提问by Amadan

I'm an Xcode newbie, and I'm trying to make my first training app. Since apparently Empty Application template is the only template that offers pre-integrated Core Data, I choose that. However, after that, I can't get UI to work (it remains empty).

我是 Xcode 新手,我正在尝试制作我的第一个培训应用程序。由于显然 Empty Application 模板是唯一提供预集成核心数据的模板,因此我选择了它。但是,在那之后,我无法让 UI 工作(它仍然是空的)。

What I did:

我做了什么:

  • Empty Application template
  • New iPad Storyboard file
  • Splashed Tab Bar Controller onto it
  • Changed Main Storyboard in Project's Summary view
  • Hit ?R
  • Stared at pure-white iPad screen, without any tabs
  • 空应用模板
  • 新的 iPad 故事板文件
  • 将标签栏控制器泼到其上
  • 更改了项目摘要视图中的主故事板
  • ?R
  • 盯着没有任何标签的纯白色 iPad 屏幕

I tried diffing against another project that I created as a Tab Bar Application (which does reflect my Storyboard changes), without any insight.

我尝试与我作为 Tab Bar 应用程序创建的另一个项目(它确实反映了我的故事板更改)进行了比较,但没有任何洞察力。

回答by Robin Summerhill

Comment out (or remove) the window creation and display code in AppDelegate.m as follows:

注释掉(或删除)AppDelegate.m 中的窗口创建和显示代码,如下所示:

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

    return YES;
}

When using a storyboard, a main UIWindow is created for you automatically. What is happening in your case is that you are creating another white window and putting it over the top of the tab UI.

使用故事板时,会自动为您创建一个主 UIWindow。在您的情况下发生的情况是您正在创建另一个白色窗口并将其放在选项卡 UI 的顶部。

ALSO- note that the Master/Detail template also gives you a core data option.

另外- 请注意,主/明细模板还为您提供了一个核心数据选项。

回答by Scott Gardner

For an Empty Application project, you have to do two things, after you've added your Storyboard file...

对于 Empty Application 项目,在添加 Storyboard 文件后,您必须做两件事...

  1. Add a row to your project Info.plist file:

    Key: Main storyboard file base name
    Value: Storyboard
    

    (or whatever you named your storyboard file)

  2. Delete the contents of application:didFinishLaunchingWithOptions:except return YES;:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        return YES;
    }
    
  1. 在您的项目 Info.plist 文件中添加一行:

    Key: Main storyboard file base name
    Value: Storyboard
    

    (或任何您命名故事板文件的名称)

  2. 删除application:didFinishLaunchingWithOptions:except的内容return YES;

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        return YES;
    }
    

回答by Jim

The Master-Detail and Utility project templates also offer Core Data as an option.

Master-Detail 和 Utility 项目模板还提供 Core Data 作为选项。

The Apple templates for Core Data are pretty horrible. They stuff far too much functionality into the app delegate and they use lazy loading unnecessarily, which just complicates things even further.

Core Data 的 Apple 模板非常糟糕。他们在应用程序委托中填充了太多功能,并且不必要地使用延迟加载,这只会使事情变得更加复杂。

You're better off looking at the generated code and adding the functionality as a separate class in a project you start without Core Data.

您最好查看生成的代码并将功能作为一个单独的类添加到一个没有 Core Data 的项目中。

To answer your immediate question though, the default empty template creates a window programmatically in the app delegate's application:didFinishLaunchingWithOptions:method. The story board sets a window up itself, so you need to remove that code from the app delegate. The only thing you need in that method is return YES;.

不过,要回答您的直接问题,默认的空模板会在应用程序委托的application:didFinishLaunchingWithOptions:方法中以编程方式创建一个窗口。故事板会自行设置一个窗口,因此您需要从应用程序委托中删除该代码。在该方法中您唯一需要的是return YES;.