Core data 访问实体中的1:N关系时出现问题
我有实体:银行、部门、分部、集合、问题。 我在访问实体部分中的关系“NSSet SUBSITION”时遇到问题,并且从此代码中获取消息“[UITableViewCell thesubsection]:无法识别的选择器已发送到实例” 在vc.m中,它填充tableview单元格Core data 访问实体中的1:N关系时出现问题,core-data,Core Data,我有实体:银行、部门、分部、集合、问题。 我在访问实体部分中的关系“NSSet SUBSITION”时遇到问题,并且从此代码中获取消息“[UITableViewCell thesubsection]:无法识别的选择器已发送到实例” 在vc.m中,它填充tableview单元格 - (NSArray *)allQuestions { NSSortDescriptor *division = [NSSortDescriptor sortDescriptorWithKey:@"subdivision
- (NSArray *)allQuestions
{
NSSortDescriptor *division = [NSSortDescriptor sortDescriptorWithKey:@"subdivision" ascending:YES];
return [_section2.thesubsection sortedArrayUsingDescriptors:@[division]];
}
但是,我可以使用此代码访问银行实体中的“NNSet部分”关系
NSSortDescriptor *division2 = [NSSortDescriptor sortDescriptorWithKey:@"division" ascending:YES];
return [self.detailItem2.thesection sortedArrayUsingDescriptors:@[division2]];
_第2节在CRSubsectionVC.h中声明 @属性(强,非原子)部分*第2部分 故事板是 1.CRMasterViewController,将银行实体中的“类别”属性显示到表视图中
Bank.h
@class Section;
@interface Bank : NSManagedObject
@property (nonatomic, retain) NSString * category;
@property (nonatomic, retain) NSSet *thesection;
@end
Bank.m
@implementation Bank
@dynamic category;
@dynamic thesection;
@end
Section.h
@class Bank, Subsection;
@interface Section : NSManagedObject
@property (nonatomic, retain) NSString * division;
@property (nonatomic, retain) Bank *bank;
@property (nonatomic, retain) NSSet *thesubsection;
@end
Section.m
@implementation Section
@dynamic division;
@dynamic bank;
@dynamic thesubsection;
@end
Subsection.h
@class Section, Set;
@interface Subsection : NSManagedObject
@property (nonatomic, retain) NSString * subdivision;
@property (nonatomic, retain) Section *section2;
@property (nonatomic, retain) NSSet *set;
@end
Subsection.m
@implementation Subsection
@dynamic subdivision;
@dynamic section2;
@dynamic set;
@end
解决了这个问题。一种不完全从工作模板复制代码并理解核心数据和表视图的情况。在哪里声明了
\u section2
,您在哪里为其赋值?\u section2在CRSubsectionVC中声明。h我添加了故事板如何与实体交互以使问题更清楚。