2011-11-22 12 views
0

我有20 htmls,我在webview中加載它。 但是,我創建了3個放置在scrollview上的webviews,並重復使用這些webviews直到html計數完成。 我在在objective-c中fastview中快速加載webview?

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 

加載HTML內容並同時滾動網頁視圖加載slowly.i要加載這些網頁視圖快速度。如何做it.can誰能幫我.Thanks提前。

+0

更新了樣品。 –

回答

0

一種可能的解決方案是在顯示之前下載並緩存所有頁面。

看到這個答案下載HTML網頁並寫在本地。

https://stackoverflow.com/q/5607132/300972

創建到這些頁的引用數組,然後將它們加載到相應的UIWebView的在scrollViewDidEndDecelerating

更新:

使用上面的鏈接,它看起來像這樣。請注意,我沒有測試過這個。

// NSArray *urls; 
// NSMutableArray *filePaths; 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    urls = [NSArray arrayWithObjects:@"http://www.url1.com", @"http://www.url2.com", @"http://www.url3.com", nil]; 

    for (int i=0; i<[urls count]; i++) 
    { 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *filePath = [NSString stringWithFormat:@"%@/%@.html", [paths objectAtIndex:0], [urls objectAtIndex:i]]; 

     NSURL *url = [NSURL URLWithString:[urls objectAtIndex:i]]; 
     NSData *urlData = [NSData dataWithContentsOfURL:url]; 
     [urlData writeToFile:filePath atomically:YES]; 
    } 
} 

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
{ 
    // Do some calculation to find index of webpage, this depends on 
    // the size of the scrollview and the size of the webview. 
    int index = ...; 

    NSString *filePath = [NSString stringWithFormat:@"%@/%@.html", [paths objectAtIndex:0], [urls objectAtIndex:i]]; 
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];  
} 
+0

如何創建緩存並執行操作。如果有任何樣本請告訴我 – Univer