[英]Passing a core data object to a sub view on didSelectRowAtIndexPath
I have a core data setup that has 2 database entities. 我有一个核心数据设置,有2个数据库实体。 For the sake of names I'll call them Primary and Secondary.
为了名字我会称他们为小学和中学。 Secondary only belong to one Primary (relationship is setup).
辅助仅属于一个主要(设置关系)。 In my main view that lists the Primary objects in a table I retrieved them and put them in an PriObject Class which stores it's properties (including the managed object ID).
在我的主视图中,列出了表中的Primary对象,我检索了它们并将它们放在一个PriObject类中,该类存储它的属性(包括托管对象ID)。 The PriObject is then added to a mutable array (priArray), which is then used to fill the table with the data.
然后将PriObject添加到可变数组(priArray)中,然后使用该数组将数据填充到表中。 All works ok so far.
到目前为止一切正常。 When I then click on the row I can log the PriObject.moID.
当我单击该行时,我可以记录PriObject.moID。
I can't figure out how to lookup that object in the database so I can then add Secondary objects to it. 我无法弄清楚如何在数据库中查找该对象,以便我可以向它添加辅助对象。 I can't do it by name because some Primary might have the same name.
我无法通过名称来执行此操作,因为某些主节点可能具有相同的名称。
I need to work out how to get an object back from either the URI or the ID. 我需要弄清楚如何从URI或ID中获取对象。 I have the ID so I can generate the URI if I need to.
我有ID,所以如果需要我可以生成URI。
Can't get my head around it at all and any examples I have found while looking don't cover what I need. 根本无法理解它,我看到的任何例子都没有涵盖我需要的东西。 What options are there?
有什么选择?
EDIT: I am currently getting all my objects with the following. 编辑:我目前正在使用以下内容获取所有对象。
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Primary"
inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSError *error;
NSArray *objects = [context executeFetchRequest:request
error:&error];
if ([objects count] == 0) {
NSLog(@"Nothing found");
} else {
NSLog(@"Something found");
}
How can I change this for just the one using: 如何使用以下内容更改此选项:
ObjectWithID:
Call the objectWithID:
method on your NSManagedObjectContext
instance to retrieve the instance. 在
NSManagedObjectContext
实例上调用objectWithID:
方法以检索实例。
As an aside, it seems like you are making things harder on yourself with this PriObject
class, it seems to be a wrapper around your NSManagedObject
instances, is that right? PriObject
一下,看起来你正在使用这个PriObject
类让自己变得更难,它似乎是你的NSManagedObject
实例的包装,是吗? I'd just use NSManagedObject
subclasses directly, personally. 我个人直接使用
NSManagedObject
子类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.