在用户在模态视图控制器中按下“登录”后,我试图显示一个UIAlertView
with 。UIActivityIndicator
要登录,凭据将发送到使用类的sendAsynchronousRequest:queue:completionHandler:
服务器NSURLConnection
。我的实现如下:
UIAlertView * spinner = [[UIAlertView alloc] initWithTitle:@"Connecting to server..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[spinner show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(spinner.bounds.size.width * 0.5f, spinner.bounds.size.height * 0.5f+5.0f);
[indicator startAnimating];
[spinner addSubview:indicator];
[indicator release];
[NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * res, NSData * data, NSError * err) {
[spinner dismissWithClickedButtonIndex:0 animated:YES];
[spinner release];
...
}
如果无法访问服务器或服务器速度很慢,这似乎可以正常工作,但如果服务器立即回复,则微调器似乎在控制台日志记录后 3-5 秒后才被关闭
wait_fences: failed to receive reply: 10004003
我认为发生这种情况是因为我正在关闭模式视图控制器(登录屏幕),而UIAlertView
它仍在显示,但我不确定为什么会发生这种情况,因为它通常应该被关闭。我做错了什么,正确的做法是什么?