tags:

views:

14

answers:

1

I am using following method to get back an NSDictionary object in ViewDidAppear. But when I attempt to access it in CellForRowAtIndexPath() it is always nil. I have tried adding an extra retain and copy to it, but it still gets released. I have been pulling my hair for 3 hours now. Any help would be appreciated.

Excerpt :

@property(nonatomic, retain) NSDictionary* userInfoObj;  

- (void) viewDidAppear:(BOOL)animated  
{  
 [super viewWillAppear:animated];  
        **//The object has data in it at this point**  
 self.UserInfoObj  = [self getUserInfo];  

}  

- (NSDictionary*)getUserInfo  
{  
 JsonHelper *helper=[[JsonHelper alloc] autorelease];  
 NSString* apiURL = [self.appDelegate urlGetUserInfo];  
 apiURL = [apiURL stringByReplacingOccurrencesOfString:@"{user_id}" withString:[UserSettings lastLoginUserId]];   
 return [helper getJsonDictionaryFromWebMethod:apiURL];  
}  


- (NSDictionary*)getJsonDictionaryFromWebMethod :(NSString*) url  
{  
.....  
.....  
....  
 // Get JSON as a NSString from NSData response  
 NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];  

 // parse the JSON response into an object  
 // Here we're using NSArray since we're parsing an array of JSON status objects  
 dict = [[parser objectWithString:json_string error:nil] retain];  

 return dict;  
}  
A: 

Try putting self.UserInfoObj = [self getUserInfo]; in the viewDidLoad delegate method instead.

Evan Mulawski
Thanks. That did the trick! Wohoo! But why was that happening. I would like to call that API every time the view is shown not just once. That is why I had it in viewDidAppear. Also, this view is loaded from a UITabBar (i.e user clicks on Tab# 3 and the view gets loaded)
Nick Brunch
(As a side note, you have the incorrect super method inside of the viewDidAppear delegate method, they should match.) I have been trying to figure out the same question, but I found that using NSLog("This method was called!") inside of the view's delegate methods helps to narrow down the ones that respond to certain events.
Evan Mulawski