我正在使用 ASIHttpRequest 从 xml 文件接收数据。但是,在异步请求期间,只要我更改 View (使用导航 Controller 返回到先前的 View ),应用程序就会崩溃并在 main.m 上显示 EXC_BAD_ACCESS
这只会在发出请求时发生。
下面是我的代码:
-(void)ProcessXML{
//Set url from string to url
NSURL *theurl = [NSURL URLWithString:@"http://twitter.com/statuses/user_timeline/2smssupport.xml"];
asirequest = [ASIHTTPRequest requestWithURL:theurl];
[asirequest setDelegate:self];
[asirequest startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"Saving to Defaults");
NSData *responseData = [request responseData];
xmlSaved = responseData;
prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:responseData forKey:@"xmlDownload"];
rssParser = [[RssParser alloc] loadXMLbyURL:xmlSaved];
[self.tableView reloadData];
NSLog(@"%@",[prefs dataForKey:@"xmlDownload"]);
}
Process XML 方法触发请求,然后接收到的数据在 RequestFinished 中处理。
我在 ASIHTTPRequest 中一定缺少某些东西,但我不知道它是什么?
谢谢
最佳答案
这段代码应该可以修复它:
-(void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[request clearDelegatesAndCancel]
}
关于iphone - 更改 View 时 ASIHTTPRequest 异步崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6307103/