[英]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.