Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Core data 访问实体中的1:N关系时出现问题_Core Data - Fatal编程技术网

Core data 访问实体中的1:N关系时出现问题

Core data 访问实体中的1:N关系时出现问题,core-data,Core Data,我有实体:银行、部门、分部、集合、问题。 我在访问实体部分中的关系“NSSet SUBSITION”时遇到问题,并且从此代码中获取消息“[UITableViewCell thesubsection]:无法识别的选择器已发送到实例” 在vc.m中,它填充tableview单元格 - (NSArray *)allQuestions { NSSortDescriptor *division = [NSSortDescriptor sortDescriptorWithKey:@"subdivision

我有实体:银行、部门、分部、集合、问题。 我在访问实体部分中的关系“NSSet SUBSITION”时遇到问题,并且从此代码中获取消息“[UITableViewCell thesubsection]:无法识别的选择器已发送到实例” 在vc.m中,它填充tableview单元格

- (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
  • 当我点击“类别”时,我会继续并将一个银行对象传递给CRDetailViewController。我使用以下代码:

    NSSortDescriptor*division2=[NSSortDescriptor SortDescriptor With Key:@“division”升序:是]; 返回[self.detailItem2.thesection SorterDarray(使用描述符):@[division2]]

  • 将节关系(NSSet*thesection)'division'属性从Bank提取到tableview中

    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
    
  • 如果我点击一个“节”,我将继续并将一个节对象传递给名为_section2的CRSubsectionVC。当我尝试访问NSSet*子部分以使用代码获取“subdivision”属性时

    NSSortDescriptor*division=[NSSortDescriptor sortdescriptor with key:@“subsection”升序:YES]; 返回[_第2节。使用描述符对子节进行排序:@[division]

  • 我收到错误[UITableViewCell thesubsection]:无法识别的选择器发送到实例。我不明白为什么自动存取器“thesection”可以正常工作,而“thesubsection”却不能

    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我添加了故事板如何与实体交互以使问题更清楚。