简体   繁体   中英

UIWebView in UITableViewCell for showing icons

I am using a UIWebView in my UITableViewCell definition to show item icons:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell) {
    cell = [[[NSBundle mainBundle] loadNibNamed:@"PostCell" owner:self options:nil] objectAtIndex:0];
}
NSDictionary *post = [posts objectAtIndex:indexPath.row];

UIWebView *iconWebView = (UIWebView*)[[cell contentView] viewWithTag:1];
[iconWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[post objectForKey:@"mMediumResImage"]] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60.0f]];

the mMediumResImage is a url pointing to an image with size around 40-60 kb.

the number of rows the UITableView is holding is ~20-30.

There is no intended functionality of the icon other than looking at it, no user-interaction. I would rather use a UIWebView than to setup a queue to load each icon into an array, requiring me to keep track of my loading process, what indexpath to update once complete, etc.. This method allows me to quickly and simply show an icon.

Is this use of a UIWebView discouraged?

If so, what do you suggest as an alternative?

That seems a little heavy handed to me. I recommend you study this bit of sample code from apple: LazyTableImages . What you have now is working, so that's good. When you get time, circle back around and optimize it using the techniques illustrated in that sample.

The LazyTableImages sample has a UITableView with the top iPhone applications. It gets the apps and their icons from an RSS feed. The app icons are "lazy loaded" as needed, so the list will appear quickly and scroll smoothly. IMO, it's well worth studying what they did there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM