https://github.com/lokming/QuestionBank
我有实体:银行,部门,分部,集,问题。 我在访问关系时遇到问题" NSSet Subsection"在实体部分并获取消息" [UITableViewCell thesubsection]:无法识别的选择器发送到实例"从这段代码 在CRSectionVC.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]];
_section2在CRSubsectionVC.h中声明 @property(强,非原子)Section * section2;
故事板是 1. CRMasterViewController,它将Bank实体的“category”属性显示为tableview,
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
当我点击“类别”时,我会将一个Bank对象传递给CRDetailViewController。我使用以下代码:
NSSortDescriptor * division2 = [NSSortDescriptor sortDescriptorWithKey:@" division"升序:YES]; return [self.detailItem2.thesection sortedArrayUsingDescriptors:@ [division2]];
从Bank获取段关系(NSSet * thisction)'division'属性到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
如果我点击'section''我会将一个Section对象传递给名为_section2的CRSubsectionVC。当我尝试访问NSSet * thesubsection以使用代码
获取'subdivision'属性时NSSortDescriptor * division = [NSSortDescriptor sortDescriptorWithKey:@" subdivision" ascending:YES]; return [_section2.thesubsection sortedArrayUsingDescriptors:@ [division]];
我收到错误[UITableViewCell thesubsection]:无法识别的选择器发送到实例。我无法弄清楚为什么自动访问器'thisction'工作正常而不是'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
答案 0 :(得分:0)
修正了问题。这种情况不是完全从工作模板中复制代码并理解核心数据和表视图。