IOS _ 3rd library SDWebImage
1. Add the downloaded source code package of the 3rd-party class library SDWebImage to the project.
2. Go to Build Phases of the project and add all. m files in the source code package to the project.
3. Import the built-in frameworks of the 3rd-party Class Library: MapKit. framework and ImageIO. framework.
4. Add the main header file "UIImageView + WebCache. h" of the 3rd-party class library"
Code snippet:
-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * cellID = @ "Beyond"; UITableViewCell * cell = [tableView progress: cellID]; if (cell = nil) {// if the pool is not obtained, a new cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: cellID] is generated.} // set the unique content Status ** s = _ statuses in the cell. [IndexPath. row]; cell. textLabel. text = s. text; cell. detailTextLabel. text = s. user. screenName; cell. textLabel. numberOfLines = 0; // important ~ Using SDWebImage of the 3rd-party framework, the cache policy is: request upon failure, disk cache, and image download suspended when scrollView is rolled [cell. imageView setImageWithURL: [NSURL URLWithString: s. user. profileImageUrl] placeholderImage: [UIImage imageNamed: @ "avatar_default.png"] options: SDWebImageLowPriority | SDWebImageRefreshCached | cached]; // return cell ;}
Key code and Cache Policy:
Request again after failure: SDWebImageRetryFailed
Disk cache: SDWebImageRefreshCached
Pause downloading when scrollView is rolling. Image: SDWebImageLowPriority
[Cell. imageViewSetImageWithURL: [NSURLURLWithString: s. user. profileImageUrl]PlaceholderImage: [UIImageimageNamed: @ "avatar_default.png"]Options: SDWebImageLowPriority | SDWebImageRefreshCached | SDWebImageRetryFailed];