In a navigation based app, I initialize an array in my app delegate without using self. When accessed in the RootViewController's cellForRowAtIndexPath:, all array objects are there and I can see it is an NSCFArray. Once the app loads, I click a table cell and in didSelectRowAtIndexPath:, that same array has a type of NSArray, no objects and I get a EXC_ BAD_ACCESS error. If I precede the array with self in the app delegate, all is fine. Why is that?
Below is the app delegate .h file:
@interface MyAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
NSMutableDictionary *aDict;
NSArray *aArray;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) NSArray *aArray;
@property (nonatomic, retain) NSArray *aDict
@end
The array and dictionary are synthesized in the .m file. I initialize the array in the app delegate .m file like this:
aArray = [self.aDict allKeys];
It is accessed like this in both root controller methods:
theDelegate = [[UIApplication sharedApplication] delegate];
[theDelegate.aArray objectAtIndex:2];
Only when I reach didSelectRowAtIndexPath: does it fail. Doing this in the app delegate makes everything work:
self.aArray = [self.aDict allKeys];
I didn't do anything to myArray between cellForRowAtIndexPath: and didSelectRowAtIndexPath:. Why does it fail in the first scenario?