2014-11-04 92 views
0

https://github.com/lokming/QuestionBank在实体中访问1:N关系的问题

我有实体:Bank,Section,Subsection,Set,Question。 我有在实体部分访问的关系“的NSSet分段”和获取消息的问题:从该代码中 CRSectionVC.m填充一个的tableview细胞

- (NSArray *)allQuestions 
{ 
NSSortDescriptor *division = [NSSortDescriptor sortDescriptorWithKey:@"subdivision" ascending:YES]; 
return [_section2.thesubsection sortedArrayUsingDescriptors:@[division]]; 
} 

“[的UITableViewCell thesubsection]无法识别的选择发送到实例”我可以使用此代码

NSSortDescriptor *division2 = [NSSortDescriptor sortDescriptorWithKey:@"division" ascending:YES]; 
return [self.detailItem2.thesection sortedArrayUsingDescriptors:@[division2]]; 

_section2在CRSubsectionVC.h宣布然而访问银行实体的“NNSet部分”关系 @property(强,非原子)第*第2节;

故事板是 1. CRMasterViewController其显示从银行实体 '类别' 属性成的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”ascending:YES]; return [self.detailItem2.thesection sortedArrayUsingDescriptors:@ [division2]];

  • 从bank中获取节段关系(NSSet * thesection)'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 
    
  • 如果我一个轻按“部分””我原因请看并传递一个节目的是CRSubsectionVC命名_section2。当我尝试访问NSSet *时,使用代码

    NSSortDescriptor * division = [NSSortDescriptor sortDescriptorWithKey:@“subdivision”ascending:YES]来获取'subdivision'属性。 return [_section2.thesubsection sortedArrayUsingDescriptors:@ [division]];

  • 我得到错误[UITableViewCell 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

    “_section2”声明在哪里,你在哪里给它赋值? – 2014-11-04 17:18:59

    +0

    _section2在CRSubsectionVC.h中声明我已经添加了故事板如何与实体进行交互以使问题更清晰。 – Lok 2014-11-05 03:55:15

    回答

    0

    解决了这个问题。不能完全从工作模板复制代码并理解核心数据和表视图的情况。