webview中多次加载网页的速度较慢

时间:2012-03-17 14:10:13

标签: iphone ipad uiwebview

我正在开发一个示例iPad应用程序,我在UIWebview中显示了一些webapages,代码运行正常。但我认为网页花费了太多时间加载到UIWebview。我的代码如下:

-(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];


}

那么我怎样才能让它更快,请指导我。

1 个答案:

答案 0 :(得分:0)

为此你必须使用NSOpertaionQueue或GCD队列是另一种选择