取消NSMutableRequest和XML解析方法目标C.

时间:2011-11-19 00:22:44

标签: objective-c xml-parsing ios-4.2 nsurlrequest

如果用户选择其他视图,我需要取消NSMutableRequest和XMLParsing

我在ViewDidLoad上执行此操作:

NSMutableURLRequest * req = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:endereco]
                                                        cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];

conn = [NSURLConnection connectionWithRequest:req delegate:self];

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

if(conn)
{
    receivedData = [[NSMutableData alloc]init];
    [DSBezelActivityView newActivityViewForView:self.view withLabel:@"Obtendo Lista..."];
}

我知道我必须:[conn cancel];在viewWillDisappear上,但我如何检查我的连接是否正在发生,所以我可以取消它? 解析方法也是如此:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

    NSXMLParser * parser = [[NSXMLParser alloc]initWithData:receivedData];
    [parser setDelegate:self];
    [parser parse];
    [parser release];
    [receivedData release];
}

0 个答案:

没有答案