Objective C Custom Lazy Load Images UITableView Cell

前端 未结 2 2049
长情又很酷
长情又很酷 2020-12-21 16:31

First time loading remote images into an iPhone app, and would like some help optimizing the process. What I\'ve currently done is get the image if it doesn\'t exist, and ca

相关标签:
2条回答
  • 2020-12-21 17:15

    2 suggestions: 1. Don't store images in NSUserDefaults, that is more suitable for user preferences, like strings.

    1. Don't do the unarchive operation twice. Just do it, then check the results.

    Replace this:

    if ([NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"Settings_SFCCovers%@_%@", retina, cell.cid]]]) {
    thumb = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"Settings_SFCCovers%@_%@", retina, cell.cid]]];
    

    With this:

    thumb = [NSKeyedUnarchiver unarchiveObjectWithData:[[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"Settings_SFCCovers%@_%@", retina, cell.cid]]];
     if ( thumb ) ... 
    
    0 讨论(0)
  • 2020-12-21 17:17

    Just having a quick look at your code - you seem to be pushing blocks onto asynchronous queues, but you are calling UI code in those blocks.

    You should only run UI code on the main thread.

    As for a solution - have a look at some of the open source implementations to either give you an idea of what you should be doing, or just use them directly.

    One such is AsyncImageView on Github.

    There are others that a quick search will bring up.

    0 讨论(0)
提交回复
热议问题