0

In my app a web view is shown inside each cell of a table view. To increase the response I we decided to save web page as images. So I made a web view which is not visible and loaded each page one by one and created the image of the page on

- (void)webViewDidFinishLoad:(UIWebView *)webView

The image is created, but even images are missing and odd images are created twice. That is if I am creating four images say image1, image2, image3, image4 . The first and second image are the same image2 will be missing then third and fourth are same and image4 will be missing.

Does anyone have any idea what's happening? How can I get all images?

EDIT: code for saving image

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    CGSize pageSize = webView.frame.size;
    UIGraphicsBeginImageContext(pageSize);

    CGContextRef resizedContext = UIGraphicsGetCurrentContext();
    [[webView layer] renderInContext:resizedContext];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
    NSData* imageData = UIImageJPEGRepresentation(image, 1.0);

    NSString  * filName;

        filName=[NSString stringWithFormat:@"%@_Potrait_%d.jpg",[currentSctionItem. titleName stringByReplacingOccurrencesOfString:@" " withString:@"_"],fileSavingAtIndex];

    NSString * filePath = [documentsDir stringByAppendingPathComponent:filName];
    [imageData writeToFile:filePath atomically:NO];
    NSLog(@"File created At path:%@",filePath);

    fileSavingAtIndex++;


        if (fileSavingAtIndex>=currentSctionItem.numberOfPagesLandscape) {
           //stop    
        }
        else{
            [webView loadHTMLString:[currentSctionItem potaraitHtmlAtThePage:fileSavingAtIndex] baseURL:baseURL]; 
        }
Eldhose
  • 726
  • 8
  • 19
  • how are you saving the images, is your code thread safe? – tkanzakic Feb 07 '13 at 10:38
  • why dont you use the webview cache mechanism ??http://stackoverflow.com/questions/1348696/how-to-cache-content-in-uiwebview-for-faster-loading-later-on – Lithu T.V Feb 07 '13 at 12:57
  • I used it (code not shown) but there is flickering on table scrolling client wants to avoid flickering. – Eldhose Feb 08 '13 at 03:44

1 Answers1

0

I fixed it by creating a new web view for each page load. It is not the correct way but now it works

if (fileSavingAtIndex>=currentSctionItem.numberOfPagesLandscape) {

            }
            else{
                UIWebView * webVw =[[UIWebView alloc] initWithFrame:PotraitwebViewFrame];
                 webVw.delegate=self;
                [webVw loadHTMLString:[currentSctionItem potaraitHtmlAtThePage:fileSavingAtIndex] baseURL:baseURL];
            }
Eldhose
  • 726
  • 8
  • 19