2011-03-23 39 views
1

我一直在阅读NSURLRequest timeOut的一些问题,但我没有看到我的问题的答案。 嗯,这里是:我的NSURLRequest对象工作正常,但如果连接超时时间超过3,我需要向用户显示一些警报。我知道如何处理该超时。 任何帮助真的很感激它。NSURLRequest timeOut handling

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:3] ; 
[webView setDelegate:self]; 
[webView loadRequest:requestObj]; 

回答

2

定义委托网络视图 - 在您的视图控制器的@interface定义添加<UIWebViewDelegate>,然后在界面生成器连接起来

然后添加一个方法

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
{ 

// whatever you want to do if it times out (or some other error) 

} 
+0

这工作第一次尝试! 非常感谢! – 2011-03-23 17:02:58