Sorry, beginner here . . .
So I create an NSMutableDictionary in my app delegate when the application launches, and then later pass it on to a view controller, as it contains options for the VC like a background image, a url I want to parse, etc.
Anyway, i wrote a custom init method for the VC, initWithOptions, where I pass the dictionary on. I’m trying to use this dictionary later on in other methods – so I created a NSMutableDictionary property for my VC and am trying to store the passed options dictionary there. However, when I go to get the contents of that property in later methods, it returns null. If i access it from the init method, it works. heres some sample code:
-(id)initWithOptions:(NSMutableDictionary *)options {
self = [super init];
if (self) {
// Custom initialization
self.optionsDict = [[NSMutableDictionary alloc]initWithDictionary:options];
NSLog(@"dictionary in init method %@",self.optionsDict);
that NSLog logs the contents of the dictionary, and it looks like its working. then later when I do this:
- (void)viewDidLoad
{
SDJConnection *connection = [[SDJConnection alloc]init];
self.dataArray = [connection getEventInfoWithURL:[self.optionsDict objectForKey:@"urlkey"]];
NSLog(@"dictionary in connection contains: %@", [self.optionsDict objectForKey:@"urlkey"]);
[_tableView reloadData];
the dictionary returns null. Ive tried adjusting the property attributes, and it didn’t work with either strong or retain. Any ideas??
THANKS!!
This happens to me sometimes. You forgot to call
[super viewDidLoad]so your properties will not be created. Your viewDidLoad will take the place of UIViewController’s viewDidLoad.