Предположим, у меня есть два класса A и B. класс A вызывает асинхронный метод Foo в классе B. Метод Foo извлекает данные с использованием асинхронного ASIHTTPRequest и отправляет данные из Foo обратно в качестве возвращаемого значения в класс A. Класс A будет использовать это возвращай данные и делай вещи
Я создаю объект моего класса URLParser здесь в другом классе и вызываю функцию getJsonUrl, она проанализирует и получит URL-адрес json для меня. Я использую этот возвращенный URL-адрес в другом ASIHTTPRequest здесь. Но я получаю EXC_BAD_ACCESS ... помогите мне разобраться ...
......
URLParser *urlParser = [[URLParser alloc] init];
NSString *JsonString = [urlParser getJsonUrl:@"http://mywebs.com/?q=iphone/news"];
NSLog(@" url returned = %@" ,JsonString);
NSURL *JsonUrl = [NSURL URLWithString:JsonString];
newsRequest = [ASIHTTPRequest requestWithURL:JsonUrl];
[newsRequest setDelegate:self];
[newsRequest startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
newsDictionary = [[NSMutableDictionary alloc] init];
NSData *responseData = [request responseData];
NSString *response = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding] ;
self.newsDictionary = [response JSONValue];
[response release];
[self getDataNews:self.newsDictionary];
}
URL-анализатор класса
@synthesize albumDic;
@synthesize GlobalRequest;
-(NSString*)getJsonUrl:(NSString *)url{
GlobalRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:url]];
[GlobalRequest setDelegate:self];
[GlobalRequest startAsynchronous]; // when i called the [GlobalRequest startSynchronous] ....both cases m getting the same error
return JsonStr;
}
- (void)requestFinished:(ASIHTTPRequest *)request{
albumDic = [[NSMutableDictionary alloc] init];
NSData *responseData = [request responseData];
NSString *response = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding] ;
self.albumDic = [response JSONValue];
[response release];
[self GetDictionary:self.albumDic];
}
- (void)requestFailed:(ASIHTTPRequest *)request{
[request cancel];
}