UIWebView - Load images only once

Hello,
I’ve an app that shows local html code inside tableview cells. The html code can include image tags, therefore I want to buffer the binaries. Otherwise the images would be loaded each time the cellForRowAtIndexPath is called.
The idea is that I download the images of the current UIWebView in the cellForRowAtIndexPath event and save them to an array. Next time the UIWebView wants to load the same html code I could load the binaries from the array.
How would you realize this? I really have no idea…

Another question is about getting the right height of the UIWebView.
Inside the cellForRowAtIndexPath event I do something like this:

var web:= new UIWebView withFrame(CGRectMake(0,lastY,cellWidth,???)); 
web.loadHTMLString(aPost.Content) baseURL(nil);
web.scrollView.scrollEnabled:= false;
web.delegate:= self;

Ideas?

How about NSUrlCache? It should do this for you automatically …

NSURLCache* cache = [NSURLCache sharedURLCache];
[cache setMemoryCapacity:4 * 1024 * 1024];
[cache setDiskCapacity:512*1024];

[NSURLRequest requestWithURL:appURL
                 cachePolicy:NSURLRequestReturnCacheDataElseLoad
             timeoutInterval:10.0];

It’s not completed yet, but in the ‘dynamic cell content height’ demo you should find a working solution … :wink:
PlayingWithUITableView.rar (650.3 KB)