2013-06-21 89 views
0

嗨!我正在開發一個應用程序。我正在創建一個webview。通過使用該webview我想在第一個完成後加載下一個url。我寫的- (void)webViewDidFinishLoad:(UIWebView *)webView這樣在UIWebView中逐個加載多個URL

- (void)webViewDidFinishLoad:(UIWebView *)webView 
    { 
     [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 
     alert_View=[[UIAlertView alloc]initWithTitle:@"\n\nData sent successfully!" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil]; 
     [alert_View show]; 
     [alert_View release]; 
     [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(removeAlert:) userInfo:nil repeats:NO]; 
    } 

而且removeAlert方法看起來像

-(void)removeAlert:(id)sender 
    { 
    [alert_View dismissWithClickedButtonIndex:-1 animated:YES]; 
    [web loadRequest:[arr objectAtIndex:1]; 
    } 

arr數組包含了所有的準備請求。當這個removeAlert方法直接執行-(void)webView:didFailLoadWithError:方法被解僱。那麼請告訴我如何在第一個請求結束後加載另一個請求?

回答

0

你可以做的一種方法是委派。所以一旦你的第一個請求得到處理,你得到了迴應,你可以發送下一個。

如果您對代表不熟悉,可以撥打link來幫助您入門。

1

如果你使用ARC,你應該擺脫[alert_View release]。警報視圖可能不會保留,這可能會導致問題。

此外,請嘗試[self performSelector: @selector(removeAlert:) withObject:nil afterDelay:3.0];,看看是否有效,而不是你的NSTimer調用。