我有一个应用程序与四个选项卡。在每个选项卡中,我使用nsurlconnection连接到远程服务器,获取响应并相应显示。在测试应用程序时,我随机出现崩溃。如果我试图再次重现崩溃,我不会崩溃。我不明白什么是坠机的根源。我启用NSZombie,符号化的崩溃日志,检查内存泄漏,但没有运气。iPhone应用程序随机崩溃exc_bad_access
我在Xcode 3中启动了项目,现在我将相同的项目导入到Xcode 4.2中,那么Xcode的兼容性会有问题吗?
而且我在所有标签中使用nsurlconnection的相同名称,如 在标签1中,我将nsurlconnection定义为conn,而标签2将nsurlconnection定义为conn。
此定义是否会引发任何问题?
请帮我解决这个随机崩溃
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(label != nil){
progressView = [[ProgressView showHUDAddedTo:self.tabBarController.view animated:YES] retain];
progressView.labelText = label;
}
[request release];
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(@"didReceiveresponse");
if ([response isKindOfClass: [NSHTTPURLResponse class]]) {
if([(NSHTTPURLResponse *)response statusCode] == 200){
}
else{
//show Connection Error Alert
}
}
responseData = [[NSMutableData alloc]init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"didReceiveData");
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[progressView hide:YES];
NSLog(@"didFail");
//show failed alert
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(@"didfinish loading");
if([responseData length] > 0)
{
//handles response data
}
}
在哪里取消nsurlconnection? – MobileDev
在阅读了更多内容之后,您可能无法取消请求。所以你需要做的是确保何时请求完成它什么都不做,因为我猜目前它试图更新不同标签上的UI? – Darren
显示请求完成时调用的代码 – Darren