All- thanks for the great instruction you have provided. I think this sketch will add clarity to what I am trying to achieve.
Essentially, I want to create iPhone app that allows user to select a schoolDistrict from a tableview and the app will slide that view over and reveal the next tableview full of schools. When they select a school, the next view displays the teachers, finally, when they select a teacher, it will display the courses taught by that teacher.
So, I am trying to construct some sample data for my viewtable "drilldown" and I am struggling to populate such a hierarchical data structure.
I'm hoping the sketch below helps.
https://skitch.com/aibkwik/rqu41/photo-feb-13-10-30-15-pm.jpg
original post follows:
UPDATED: I am trying to alloc an array that is deeply embedded in an object hierarchy. The top object instance is call "thisYear" and it has an array in it called "courses". "courses" also contains, among other things, an array called scoreCatetories. How would you initialize and add an object to the "scoreCategories" array? I've tried numerous things, including:
I'm trying all manner of combinations such as the one below - nothing is working.
...
[[thisYear courses] scoreCategories] = [[NSMutableArray alloc] init];
[[[thisYear courses] scoreCategories] addObject:myNewObj];
...
I'm trying to load some sample data - the code below is located in the
didFinishLaunchingWithOptions function of the appDelegate.
Here is the code snippet that is causing me grief. Please see the .h files, further down in this post.
dGradeURin *thisYear;
thisYear = [[dGradeURin alloc] init];
[thisYear.howManyTerms initWithInteger: 4];
thisYear.gradeURin = @"Freshman";
//this paragraph compiles and runs fine
dCourse *tmpcourse;
tmpcourse = [[dCourse alloc] init];
tmpcourse.cName =@"Computer Science";
tmpcourse.school =@"Freedom High";
thisYear.courses = [[NSMutableArray alloc] init];
[thisYear.courses addObject:tmpcourse];
dScoringCategory *tmpSC;
tmpSC = [[dScoringCategory alloc] init];
tmpSC.name = @"Quizzes";
//these two lines are not working
[[thisYear courses] setScoreCategories:[[[NSMutableArray alloc] init] autorelease]];
[[[thisYear courses] scoreCategories] addObject:tmpSC];
//both the above lines compile with a warning: NSMutableArray may not responde to -setScoreCategories
// when I run the program, the first line causes crash with an exception... See stack trace at far bottom
Any help greatly appreciated.
===================
Here are the .h header file snippets for each interface object definitions, in essence...
@interface dGradeURin : NSObject {
NSNumber *howManyTerms;
NSString *gradeURin;
NSMutableArray *courses;
}
@property (retain, nonatomic) NSNumber *howManyTerms; @property (retain, nonatomic) NSString *gradeURin; @property (retain, nonatomic) NSMutableArray *courses;
@interface dCourse : NSObject {
NSString *cName;
NSString *teacher;
NSString *school;
NSString *school_term;
NSString *gradingMethod;
NSNumber *whichterm;
NSMutableArray *scoreCategories;
}
@property (retain, nonatomic) NSString *cName;
@property (retain, nonatomic) NSString *school;
@property (retain, nonatomic) NSMutableArray *scoreCategories;
@interface dScoringCategory : NSObject {
NSString *name;
NSMutableArray *scores;
}
@property (retain, nonatomic) NSString *name; @property (retain, nonatomic) NSMutableArray *scores;
@interface dScore : NSObject {
NSNumber *score;
NSDate *scoreDate;
NSString *description;
}
@property (retain, nonatomic) NSDate *scoreDate; @property (retain, nonatomic) NSNumber *score; @property (retain, nonatomic) NSString *description;
================================ Here is the stack trace
2011-02-13 21:49:43.559 GradeJanx[86526:40b] -[NSArrayM setScoreCategories:]: unrecognized selector sent to instance 0x4b76660 2011-02-13 21:49:43.561 GradeJanx[86526:40b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM setScoreCategories:]: unrecognized selector sent to instance 0x4b76660' * Call stack at first throw: ( 0 CoreFoundation 0x00db0be9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x00f055c2 objc_exception_throw + 47 2 CoreFoundation 0x00db26fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00d22366 __forwarding + 966 4 CoreFoundation 0x00d21f22 _CF_forwarding_prep_0 + 50 5 GradeJanx 0x00002c50 -[AppDelegate_iPhone application:didFinishLaunchingWithOptions:] + 881 6 UIKit 0x002ba1fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 7 UIKit 0x002bc55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439 8 UIKit 0x002c6db2 -[UIApplication handleEvent:withNewEvent:] + 1533 9 UIKit 0x002bf202 -[UIApplication sendEvent:] + 71 10 UIKit 0x002c4732 _UIApplicationHandleEvent + 7576 11 GraphicsServices 0x016e6a36 PurpleEventCallback + 1550 12 CoreFoundation 0x00d92064 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52 13 CoreFoundation 0x00cf26f7 __CFRunLoopDoSource1 + 215 14 CoreFoundation 0x00cef983 __CFRunLoopRun + 979 15 CoreFoundation 0x00cef240 CFRunLoopRunSpecific + 208 16 CoreFoundation 0x00cef161 CFRunLoopRunInMode + 97 17 UIKit 0x002bbfa8 -[UIApplication _run] + 636 18 UIKit 0x002c842e UIApplicationMain + 1160 19 GradeJanx 0x000028bc main + 102 20 GradeJanx 0x0000284d start + 53
thisYear
object isn't clear. – Nikita Rybak