2011-03-23 42 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