开发者

NDictionary getting autoreleased even after retain or copy

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.

Excer开发者_StackOverflow中文版pt :

@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;  
}  


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜