<span id="Label3"></p>1. In The. m file that needs to use the network image<p><p><span style="font-size: 18px;">Nsurl *url = [nsurl urlwithstring:imageurlstring];</span></p></p><p><p><span style="font-size: 18px;">UIImage *placeholder = [UIImage imagenamed:@ "placeholder"];</span></p></p><p><p><span style="font-size: 18px;"></span></p></p><p><p><span style="font-size: 18px;"><span style="color: #008000;">//the former: Download failed retry, the latter: low priority, if the TableView is scrolling, then pause the download, so as to avoid the list when scrolling because of the download picture of the lag</span></span></p></p><p><p><span style="font-size: 18px;">Sdwebimageoptions options = sdwebimageretryfailed | sdwebimagelowpriority;</span></p></p><p><p><span style="font-size: 18px;"></span></p></p><p><p><span style="font-size: 18px;">[self.imageview sd_setimagewithurl:url placeholderimage:placeholder options:options progress:^ (NSInteger receivedsize, nsinteger Expectedsize) { <span style="color: #008000;">//segment download, this block may be called multiple times</span></span></p></p><p><p><span style="font-size: 18px;">NSLog (@ "download progress:%f", (double) receivedsize/expectedsize); <span style="color: #008000;">//here You can monitor the progress of the download</span></span></p></p><p><p><span style="font-size: 18px;">} completed:^ (UIImage *image, nserror *error, sdimagecachetype cachetype, nsurl *imageurl) {</span></p></p><p><p><span style="font-size: 18px;">NSLog (@ "----picture loaded---%@", image); <span style="color: #008000;">//here to get pictures, can be divided into functional modules, sub-folder storage, to facilitate the development of DEBUGGING. </span></span></p></p><p><p><span style="font-size: 18px;">}];</span></p></p><p><p></p></p>2. In the APPDELEGATE.M file<p><p><span style="font-size: 18px;">/**</span></p></p><p><p><span style="font-size: 18px;">* This method is called when the app receives a memory warning.</span></p></p><p><p><span style="font-size: 18px;">*/</span></p></p><p><p><span style="font-size: 18px;">-(void) applicationdidreceivememorywarning: (uiapplication *) Application</span></p></p><p><p><span style="font-size: 18px;">{</span></p></p><p><p><span style="font-size: 18px;">Sdwebimagemanager *mgr = [sdwebimagemanager sharedmanager];</span></p></p><p><p><span style="font-size: 18px;"></span></p></p><p><p><span style="font-size: 18px;"><span style="color: #008000;">//1. Cancel the operation being downloaded</span></span></p></p><p><p><span style="font-size: 18px;">[mgr cancelall];</span></p></p><p><p><span style="font-size: 18px;"></span></p></p><p><p><span style="font-size: 18px;"><span style="color: #008000;">//2. Clear the memory cache</span></span></p></p><p><p><span style="font-size: 18px;">[mgr.imagecache clearmemory];</span></p></p><p><p><span style="font-size: 18px;">}</span></p></p><p><p>Better ways to use IOS sdwebimage</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service