xcode iphone标签栏控制器和核心数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1365792/
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-09-14 18:47:14  来源:igfitidea点击:

iphone tab bar controller and core data

iphonexcodecore-datauinavigationcontrollertabbarcontroller

提问by Sway

Ok bit of a newbie type question.

好吧,一个新手类型的问题。

I want to use Core Data, together with Tab and Navigation controllers.

我想使用 Core Data,以及 Tab 和 Navigation 控制器。

In XCode if I create a Navigation Based Application I get the option to choose Core Data. Whereas If I create a Tab Bar Application I don't get the choice.

在 XCode 中,如果我创建一个基于导航的应用程序,我可以选择核心数据。而如果我创建一个标签栏应用程序,我就没有选择。

I understand that Tab Bars display view controllers so it kinda makes sense. However given that by default it sticks the basic Core Data code in the Application delegate I don't see why this isn't offered.

我知道 Tab Bars 显示视图控制器,所以它有点道理。然而,鉴于默认情况下它在应用程序委托中粘贴基本的核心数据代码,我不明白为什么不提供。

At the moment I'm creating the two projects and cutting and pasting between them.

目前我正在创建两个项目并在它们之间进行剪切和粘贴。

Does this omission in XCode seem weird to you? Is it some sort of oversight?

你觉得 XCode 中的这个遗漏很奇怪吗?这是某种疏忽吗?

Thanks, Matt

谢谢,马特

采纳答案by Timothy Walters

The templates are designed to be more 'pure', any combination of the templates is left as an exercise for the developer.

模板被设计得更加“纯粹”,模板的任何组合都留给开发人员作为练习。

They could do a CoreData + Tab and Nav Controller template, but to be fair they'd then have to do every other combination that might be 'reasonable'.

他们可以做一个 CoreData + Tab 和 Nav Controller 模板,但公平地说,他们必须做所有其他可能“合理”的组合。

Combining them yourself isn't that hard, and there's sample apps in the dev centre that show some of the combinations within a working application.

自己将它们组合起来并不难,开发中心有一些示例应用程序,可以显示工作应用程序中的一些组合。

回答by Peter Whitfield

I've faced the same problem and ended up creating a tabBar app and adding the core data stuff later.

我遇到了同样的问题,最终创建了一个 tabBar 应用程序并稍后添加核心数据内容。

To do so, I've:

为此,我已经:

  1. added the coredata framework to my project
  2. added #import < CoreData/CoreData.h > to myproject_Prefix.pch
  3. added declarations to delegate header and getter implementations just as created by the templates that support core data
  4. create model file - add file to resources group (or wherever you want to put your model stuff) and create a data model file.
  1. 将 coredata 框架添加到我的项目中
  2. 将 #import <CoreData/CoreData.h> 添加到 myproject_Prefix.pch
  3. 添加声明以委托标头和 getter 实现,就像由支持核心数据的模板创建的一样
  4. 创建模型文件 - 将文件添加到资源组(或您想要放置模型的任何地方)并创建一个数据模型文件。

This should get you to the same point you would be at with the core data supporting templates.

这应该让您达到与核心数据支持模板相同的程度。

For your specific case (core data with tabbar), Apple have a good sample app:

对于您的特定情况(带有标签栏的核心数据),Apple 有一个很好的示例应用程序:

http://developer.apple.com/iphone/library/samplecode/iPhoneCoreDataRecipes/index.html

http://developer.apple.com/iphone/library/samplecode/iPhoneCoreDataRecipes/index.html

This shows how they pass the context through to the relevant view controller defined in the xib file which was the thing that held me up for a while.

这显示了他们如何将上下文传递给在 xib 文件中定义的相关视图控制器,这让我犹豫了一段时间。

Hope this helps.

希望这可以帮助。

Cheers, Peter

干杯,彼得

回答by Starejaz

You can add it yourself it's very simple to do:

你可以自己添加它很简单:

To modify Tab Bar template settings you have to open the following file

要修改标签栏模板设置,您必须打开以下文件

For XCode 4.2:

对于 XCode 4.2:

/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application/Tabbed Application.xctemplate/TemplateInfo.plist

To add core data option you have to add the property "com.apple.dt.unit.coreDataCocoaTouchApplication" to the Ancestors key:

要添加核心数据选项,您必须将属性“ com.apple.dt.unit.coreDataCocoaTouchApplication”添加到 Ancestors 键:

after adding the property it should look like this:

添加属性后,它应该如下所示:

<key>Ancestors</key>

<array>
<string>com.apple.dt.unit.storyboardApplication</string>
<string>com.apple.dt.unit.coreDataCocoaTouchApplication</string>
</array>

For Previous XCode Versions

对于以前的 XCode 版本

/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/Application/Tab Bar Application.xctemplate/TemplateInfo.plist

To add core data option you have to add the property "com.apple.dt.unit.coreDataCocoaTouchApplication" to the Ancestors key:

要添加核心数据选项,您必须将属性“ com.apple.dt.unit.coreDataCocoaTouchApplication”添加到 Ancestors 键:

after adding the property it should look like this:

添加属性后,它应该如下所示:

<key>Ancestors</key>

<array>
<string>com.apple.dt.unit.cocoaTouchFamiliedApplication</string>
<string>com.apple.dt.unit.coreDataCocoaTouchApplication</string>
</array>

Restart the Xcode!

重启Xcode!

Everything should work fine now:!! And you have Core Data option visible when you Create a new Tabbed Project In Xcode.

现在一切正常:!!当您在 Xcode 中创建新的选项卡式项目时,您可以看到核心数据选项。

回答by gabtub

Had to do the same, i think the easiest way is to create a "Window-based Application", then declare a tabBarController in your AppDelegate like this:

不得不做同样的事情,我认为最简单的方法是创建一个“基于窗口的应用程序”,然后在你的 AppDelegate 中声明一个 tabBarController ,如下所示:

AppDelegate.h

AppDelegate.h

@interface CommUnityAppDelegate : NSObject <UIApplicationDelegate> {
UITabBarController *tabBarController; // add this
UIWindow *window;
}

// and this
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

In your MainWindow.xib insert a TabBarController and connect it with your AppDelegates tabBarController.

在您的 MainWindow.xib 中插入一个 TabBarController 并将其与您的 AppDelegates tabBarController 连接。

After that make it visible by adding following line

之后通过添加以下行使其可见

AppDelegate.m

AppDelegate.m

- (void)applicationDidFinishLaunching:(UIApplication *)application {
  [window addSubview:tabBarController.view]; // add this
  [window makeKeyAndVisible];
}

This gives you a basic set up and from there you can easily add navigation controllers with interface builder

这为您提供了基本设置,然后您可以使用界面构建器轻松添加导航控制器