我在重新访问方法外的实例变量时遇到问题。我想访问其他方法中的值。但是当我在其他方法中打印该值时,会打印空值。所以伙计们,我需要你的帮助。如果你没有得到我的问题,请告诉我。谢谢
//I am giving a snippet of my code
//DBForHomeViewController.h class
@interface DBForHomeViewController : UIViewController{
id _jsonDB;
}
-(void)channelIDForDataBase;
-(void)openDataBase;
@end
//DBForHomeViewController.m class
@implementation DBForHomeViewController
-(void)channelIDForDataBase
{
for (NSString *pNewString in stringValueOfCIdDB) {
NSString *recentVideoUrl=[NSString stringWithFormat:@"%@%@",pNewString,fullPublishDate,];
NSURL *videoUrlPublished=[NSURL URLWithString:recentVideoUrl];
NSURLRequest *requestVideoUrlPublished=[NSURLRequest requestWithURL:videoUrlPublished];
AFJSONRequestOperation *operationURL = [AFJSONRequestOperation JSONRequestOperationWithRequest:requestVideoUrlPublished success:^(NSURLRequest *requestURL, NSHTTPURLResponse *response, id getSTATS)
{
_jsonDB= getSTATS;
// NSLog(@"DB data is:%@",_jsonDB);
//I am getting json data here.Now I want to access _jsonDB in other //method ie -(void)openDataBase)
}failure:nil];
[operationURL start];
}
}
-(void)openDataBase
{
NSLog(@"data in another class is :%@",_jsonDB);
//here I am getting _jsonDB value as null
//I want to to have _jsonDB value in this method
//
}