2012-03-17 19 views
1

UIWebviewにいくつかのwebapagesが表示されているサンプルiPadアプリを開発していますが、コードが正常に動作しています。しかし、Webページが読み込みに時間がかかりすぎると思います。私はUIWebviewです。コードは次のとおりです。webviewで複数のWebページを読み込むのが遅い

-(void)createWebView 
{ 

    //******************** First Webview********* 

    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 Webview********* 

    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 Webview************ 

    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 Webview************ 
    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]; 


} 

どのようにすれば、もっと速くすることができますか、私を案内してください。

+0

どのくらいの時間がかかりますか? Safariで4つの異なるページをロードするのに必要な時間と実装のパフォーマンスを比較していますか(これは最高のパフォーマンスとなるはずです)。私の経験では、コンテンツがローカルのHTMLであっても、WebViewsにコンテンツをロードするのが私の望むより遅いです。あなたがやっていることは何も非常に複雑または間違って見えません。したがって、可能なことについての期待を適切に設定していることを確認するために、Safariでいくつかのパフォーマンステストを行う必要があります。 – janoside

+0

NSOperationQueueまたはこれのための任意のスレッドを使用する必要がありますか? – user1227928

答えて

0

これはNSOpertaionQueueまたはGCDキューを使用する必要があります別のオプションです

関連する問題