[英]IOS/objective-c/core-data: How to get attribute from related entity
I have a detail view where I display attributes of an object from an entity in core data. 我有一个详细视图,在其中显示核心数据中实体的对象属性。
The entity has a one-to-one relationship with another entity that has other data. 该实体与具有其他数据的另一个实体具有一对一的关系。 Because I don't understand relationships that well, it may not be set up correctly. 由于我不太了解关系,因此可能无法正确设置。
How can I display data from the other entity? 如何显示其他实体的数据?
In .h file, I have: 在.h文件中,我有:
@property (nonatomic, strong) Persons *person;
@property (nonatomic, strong) Addresses *address;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
In .m file in viewDidLoad I have: 在viewDidLoad中的.m文件中,我有:
self.nameLabel.text = self.person.name;//displays fine
self.addressLabel.text = self.address.address//does not display
NSLog(@"address:%@",self.address.address);//displays (null)
Thanks for any suggestions. 感谢您的任何建议。
考虑到您已将人对象保存在视图控制器中,则只需按照person.address的关系获取其他实体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.