2012-03-17 36 views
-1

目前我正在開發一個示例,我在ipad屏幕上顯示4個webview並試圖在其中顯示4個不同的URL。如何在多個webview中停止多個活動指示器動畫?

所有的網頁都完美顯示在web視圖中。

另外,我在網頁開始加載時顯示4個活動指示器。

但我無法弄清楚如何在加載到屏幕後一個一個地停止所有相應網頁中的活動指示器。

-(void)createWebView 
{ 

    //******************** First ********* 

    firstWebView=[[UIWebView alloc]init]; 
    firstWebView.frame=CGRectMake(10, 50, 350, 470); 
    firstWebView.delegate=self; 
    firstIndicator = [[UIActivityIndicatorView alloc] 
             initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    firstIndicator.center = CGPointMake(160, 240); 
    firstIndicator.hidesWhenStopped = YES; 
    [self.firstWebView addSubview:firstIndicator]; 
    [firstIndicator startAnimating]; 
    firstWebView.backgroundColor=[UIColor grayColor]; 
    NSURL *firstUrl = [NSURL URLWithString:@"http://www.techtree.com"]; 
    NSURLRequest *firstRequestObj = [NSURLRequest requestWithURL:firstUrl]; 
    [firstWebView loadRequest:firstRequestObj]; 
    [self.view addSubview:firstWebView]; 

    //******************* Second ********* 

    secondWebView=[[UIWebView alloc]init]; 
    secondWebView.frame=CGRectMake(405, 50, 350, 470); 
    secondWebView.delegate=self; 

    secondIndicator = [[UIActivityIndicatorView alloc] 
         initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    secondIndicator.center = CGPointMake(160, 240); 
    secondIndicator.hidesWhenStopped = YES; 
    [self.secondWebView addSubview:secondIndicator]; 
    [secondIndicator startAnimating]; 
    secondWebView.backgroundColor=[UIColor grayColor]; 

    NSURL *secondUrl = [NSURL URLWithString:@"http://www.facebook.com"]; 
    NSURLRequest *secondRequestObj = [NSURLRequest requestWithURL:secondUrl]; 
    [secondWebView loadRequest:secondRequestObj]; 
    [self.view addSubview:secondWebView]; 


    //****************** Third ************ 

    thirdWebView=[[UIWebView alloc] init]; 
    thirdWebView.frame=CGRectMake(10, 528, 350, 470); 
    thirdWebView.delegate=self; 


    thirdIndicator = [[UIActivityIndicatorView alloc] 
         initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    thirdIndicator.center = CGPointMake(160, 240); 
    thirdIndicator.hidesWhenStopped = YES; 
    [self.thirdWebView addSubview:thirdIndicator]; 
    [thirdIndicator startAnimating]; 

    thirdWebView.backgroundColor=[UIColor grayColor]; 

    NSURL *thirdUrl = [NSURL URLWithString:@"http://www.yahoo.com"]; 
    NSURLRequest *thirdRequestObj = [NSURLRequest requestWithURL:thirdUrl]; 
    [thirdWebView loadRequest:thirdRequestObj]; 
    [self.view addSubview:thirdWebView]; 

    //***************** Fourth ************ 
    fourthWebView=[[UIWebView alloc] init]; 
    fourthWebView.frame=CGRectMake(405,528, 350, 470); 
    fourthWebView.delegate=self; 


    fourthIndicator = [[UIActivityIndicatorView alloc] 
         initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    fourthIndicator.center = CGPointMake(160, 240); 
    fourthIndicator.hidesWhenStopped = YES; 
    [self.fourthWebView addSubview:fourthIndicator]; 
    [fourthIndicator startAnimating]; 

    fourthWebView.backgroundColor=[UIColor grayColor]; 

    NSURL *fourthUrl = [NSURL URLWithString:@"http://stackoverflow.com"]; 
    NSURLRequest *fourthRequestObj = [NSURLRequest requestWithURL:fourthUrl]; 
    [fourthWebView loadRequest:fourthRequestObj]; 
    [self.view addSubview:fourthWebView]; 


    //******************** Memory Managemt ********** 
    [firstWebView release]; 
    [secondWebView release]; 
    [thirdWebView release]; 
    [fourthWebView release]; 

    [firstIndicator release]; 
    [secondIndicator release]; 
    [thirdIndicator release]; 
    [fourthIndicator release]; 


} 

回答

0
overwrite below delegate method and check which webview is loading finished like below 

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    if(webView== firstWebView) 
    { 
    [firstIndicator setHidden:YES]; 
    } 
    else 
    { 
    so on... 
    } 
} 
+0

由於其working.One更多的問題,我如何使它來得更快,因爲它正在採取太多的時間來加載所有網頁。 – user1227928 2012-03-17 06:15:44