https://github.com/lokming/QuestionBank
I have entities: Bank,Section,Subsection,Set,Question. I am having problems accessing relationship "NSSet Subsection" in entity Section and getting the message "[UITableViewCell thesubsection]: unrecognized selector sent to instance" from this code in CRSectionVC.m which fills a tableview cell
- (NSArray *)allQuestions
{
NSSortDescriptor *division = [NSSortDescriptor sortDescriptorWithKey:@"subdivision" ascending:YES];
return [_section2.thesubsection sortedArrayUsingDescriptors:@[division]];
}
I can however access the "NNSet section" relationship in Bank entity using this code
NSSortDescriptor *division2 = [NSSortDescriptor sortDescriptorWithKey:@"division" ascending:YES];
return [self.detailItem2.thesection sortedArrayUsingDescriptors:@[division2]];
_section2 is declared in CRSubsectionVC.h @property (strong, nonatomic) Section *section2;
The storyboard is 1. CRMasterViewController which displays ‘category’ attribute from Bank entity into a 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
When I tap a ‘category’ I segue and pass a Bank object to CRDetailViewController. I use following code:
NSSortDescriptor *division2 = [NSSortDescriptor sortDescriptorWithKey:@"division" ascending:YES]; return [self.detailItem2.thesection sortedArrayUsingDescriptors:@[division2]];
to fetch section relationship (NSSet *thesection) ‘division’ attribute from Bank into 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
If I tap a ‘section’ ’ I segue and pass a Section object to CRSubsectionVC named _section2. When I try to access NSSet *thesubsection to get ‘subdivision’ attribute using code
NSSortDescriptor *division = [NSSortDescriptor sortDescriptorWithKey:@"subdivision"ascending:YES]; return [_section2.thesubsection sortedArrayUsingDescriptors:@[division]];
I get the error [UITableViewCell thesubsection]: unrecognized selector sent to instance. I cannot figure out why automated accessor ‘thesection’ works OK but not ‘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
_section2
declared, and where do you assign a value to it? – Tom Harrington