Objective C Custom Lazy Load Images UITableView Cell

前端 未结 2 2057
长情又很酷
长情又很酷 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 ) ... 
    

提交回复
热议问题