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