简体   繁体   English

ios / xcode / objective-c:有什么方法可以链接到核心数据驱动页面中的其他视图控制器?

[英]ios/xcode/objective-c: Any way to link to other view controller in core-data driven page?

I want to do something in app that is standard and trivial on web but may not be possible in IOS. 我想在标准的应用程序中做一些简单的事情,但在IOS中可能做不到。 Just wondering if there is a way I haven't thought of. 只是想知道是否有我没有想到的方法。

Core data model based on mysql data scheme is: 基于mysql数据方案的核心数据模型是:

entity/table of cuisine types ie italian, chinese, indian etc. entity/table of restaurants entity/table of cuisine linked to restaurants 餐馆类型的实体/表,即意大利,中国,印度等。餐馆的实体/表餐馆相关的实体/表

On web, there is a page of cuisines pulled from cuisines table. 在网络上,有一个从美食表中提取的美食页面。 You can click on cuisine and it shows restaurants associated with that cuisine pulled from cuisine-restaurants table. 您可以单击美食,它会显示与从美食餐厅表中拉出的该美食相关的餐厅。 Then you can click on the restaurant and go to the restaurant detail page pulled from restaurants table. 然后,您可以单击餐厅并转到从餐厅表中拉出的餐厅详细信息页面。 Routine stuff for web. Web的常规内容。

For app, I have a view controller of cuisines that pulls from the cuisines entity. 对于应用程序,我有一个来自美食实体的美食视图控制器。 However, when you click on cuisine, I can't think of a way to get a list of restaurants associated with the cuisine from the cuisine-restaurant entity as you are now pulling from a different entity. 但是,当您单击美食时,我想不出一种方法来从美食餐厅实体中获取与该美食相关的餐馆列表,因为您现在正从另一个实体中获取食物。

If I could get this list of restaurants, I imagine I could get the restaurant detail using standard master detail patter. 如果我可以得到这家餐馆的清单,我想我可以使用标准的主细节模式来获得餐馆的详细信息。

However, I can't figure out middle step or how to put it all together. 但是,我不知道中间步骤或如何将它们放在一起。

Does anyone know of a way to do this in core data/objective-c or can recommend a tutorial that does this in core data? 有谁知道在核心数据/ objective-c中执行此操作的方法,或者可以推荐在核心数据中执行此操作的教程?

Thanks in advance for any suggestions. 在此先感谢您的任何建议。

The usual approach in Core Data would be to have a relationship from a Cuisine entity to a Restaurant entity. 核心数据中通常的方法是从Cuisine实体到Restaurant实体建立关系。 In code this would look like a set of related objects. 在代码中,这看起来像一组相关对象。 Any time you have an instance of Cuisine , you'd just ask it for the value of its restaurants property. 每当您有Cuisine实例时,您都只需要询问它的restaurants属性值即可。 In other words, once you have the cuisines, you'd already have everything you need to get a full list of restaurants for each one. 换句话说,一旦您有了美食,就已经拥有了获取每家餐馆的完整清单所需的一切。 You'd just get the collection of restaurants and then hand that off to the view controller that can display them. 您只需获取餐厅的集合,然后将其交给可以显示餐厅的视图控制器即可。

In the model editor it would look something like this: 在模型编辑器中,它将如下所示:

在此处输入图片说明

In code, once you had an instance of Cuisine , getting the restaurants for that cuisine would just be: 在代码中,一旦有了Cuisine的实例,那么得到该Cuisine的餐馆就是:

NSSet *restaurants = cuisine.restaurants;

Or if you're not using custom NSManagedObject subclasses, 或者,如果您不使用自定义NSManagedObject子类,

NSSet *restaurants = [cuisine valueForKey:@"restaurants"];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IOS / Objective-C / Core-data:如何检测选择器控制器中是否选择了新图像 - IOS/Objective-C/Core-data: How to detect if new image picked in picker controller iOS / Core-data / Objective-C:带有布尔值的NSPredicate - IOS/Core-data/Objective-C: NSPredicate with Boolean values IOS / Objective-C / Core-Data:关系对象附带新的Core Data对象吗? - IOS/Objective-C/Core-Data: Does new Core Data object come with relationship objects? iOS / Objective-C / Core-data:如何从objectID获取对象 - IOS/Objective-C/Core-data: how to get object from objectID ios / objective-c / core-data:managedobjectcontext类语法中的调用方法 - ios/objective-c/core-data: Call method in managedobjectcontext class syntax ios / objective-c / core-data:如何在NSManagedObjects中将关系显示为属性 - ios/objective-c/core-data: How to show relationship as property in NSManagedObjects iOS / objective-c / core-data:如何从相关实体获取属性 - IOS/objective-c/core-data: How to get attribute from related entity 有什么方法可以使用Objective-C iOS中所有视图控制器上可以访问的全局静态字典? - Is there any way to use global Static dictionary could able to access on all view controller in objective-c ios? ios / xcode / objective-c:导航到嵌入在导航控制器中的模态视图控制器 - ios/xcode/objective-c: Segue to modal view controller embedded in navigation controller 在使用桥接头时,如何将数据(字典)从Objective-C控制器传递到Swift“ viewcontroller”中? 还有其他办法吗? - How to pass data(dictionary) from Objective-C Controller into Swift `viewcontroller` while using bridging-header? Is there any other way?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM