У меня нет проблем запускать пример кода ниже в симуляторе iPhone, но когда я запускаю его в iPhone, я всегда получаю EXC_BAD_ACCESS, когда я вызываю [asiRequest cancel ]. любой может помочь? Благодарю.получил EXC_BAD_ACCESS, когда я отменил асинхронный веб-запрос, используя ASIHTTPRequest
ASIHTTPRequest *asiRequest;
-(IBAction)request1{
NSLog(@"request starting");
[self sendRequest];
}
-(IBAction)cancel1{
NSLog(@"request caceling");
if(asiRequest)
[asiRequest cancel];
}
-(void)sendRequest{
asiRequest=[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://maps.google.com/"]];
[asiRequest setDelegate:self];
[asiRequest startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"requestFinished");
asiRequest=nil;
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSLog(@"request Error=%@",[request error]);
asiRequest=nil;
}
После проверки API, я думаю, что я не должен выпустить его в requestFinished или requestFailed
тем, как я могу отпустить его, когда он finishs?
- (void)cancel
{
#if DEBUG_REQUEST_STATUS
NSLog(@"Request cancelled: %@",self);
#endif
[[self cancelledLock] lock];
if ([self isCancelled] || [self complete]) {
[[self cancelledLock] unlock];
return;
}
[self failWithError:ASIRequestCancelledError];
[self setComplete:YES];
[self cancelLoad];
[[self cancelledLock] unlock];
// Must tell the operation to cancel after we unlock, as this request might be dealloced and then NSLock will log an error
[super cancel];
}
Вы всегда можете нажать галочку, чтобы принять ответ: стр. –