iphone - 更改 View 时 ASIHTTPRequest 异步崩溃

标签 iphone objective-c ios cocoa-touch ios4

我正在使用 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/

相关文章:

iphone - 使用 UITabBarController 时如何共享 ManagedObjectContext

objective-c - 跟踪滑动

iphone - iOS 中的加密用法

ios - Guard Malloc 导致 wacko 应用程序行为

iphone - 在临时分发中添加新 iPhone 后是否需要重建应用程序?

ios - 应用在待审核阶段可以修改应用截图吗?

ios - 当文本字段的输入 View 不同时出现 KeyboardWillShowNotification

objective-c - -initWithContentsOfFile : for an NSMutableArray

ios - 检索特定月份中星期一的数量

ios - 在Objective-C中以相同的动画显示和隐藏UIView?