New QQ Exchange Group: 418536818, before the group is full
Originally has been used afnetworking network request and Sdwebimage function of the former also have, but the problem of cache cleanup also to solve their own, the project time is tight, so the picture of the asynchronous request had to change with Sdwebimage
1.SDWebImage Download Address Https://github.com/rs/SDWebImage.git
2. Add library This does not want to say Mapkit and ImageIO can not be less, because Sdwebimage relies on this library
3.AppDelegate Medium
Add a storage path #import "Sdwebimage/sdimagecache.h"
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
Override point for customization after application launch.
Add a generic read-only storage path
NSString * Bundlepath = [[[nsbundlemainbundle]resourcepath]stringbyappendingpathcomponent:@ "CustomPathImages"];
[[Sdimagecachesharedimagecache]addreadonlycachepath:bundlepath];
return YES;
} 4.
#import "sdwebimage/uiimageview+webcache.h" Registered God horse's seemingly no and nothing
-(void) doregister{
[Sdwebimagemanager sharedmanager].imagedownloader.username =@ "HttpWatch";
[Sdwebimagemanager sharedmanager].imagedownloader.password =@ "httpwatch01";
5. Set the order in which pictures are stored
-(void) doorder{
[sdwebimagemanager.sharedmanager.imagedownloadersetvalue:@ "Sdwebimage Demo" forhttpheaderfield:@ "AppName"];
SDWebImageManager.sharedManager.imageDownloader.executionOrder =sdwebimagedownloaderlifoexecutionorder;
6. Download pictures asynchronously
[Cell.imageview Sd_setimagewithurl:[nsurlurlwithstring:[self.arrayobjectatindex:indexpath.row]]
Placeholderimage:nil
Options:indexPath.row ==0?
SDWEBIMAGEREFRESHCACHED:0];
7. Empty Cached pictures
-(Ibaction) Doclean: (ID) Sender {
[SDWebImageManager.sharedManager.imageCacheclearMemory];
[SDWebImageManager.sharedManager.imageCacheclearDisk];
[Self.tableviewreloaddata];
}
Looks like this place needs TableView reloaddata once.
--------------------------------------------------------------------------------------------------------------- -----------below is. m file all
#import "ViewController.h"
#import "Sdwebimage/uiimageview+webcache.h"
@interface Viewcontroller () <UITableViewDataSource,UITableViewDelegate>
@property (Nonatomic,strong) nsarray * array;
@property (Weak, nonatomic) Iboutlet UITableView *tableview;
@end
@implementation Viewcontroller
-(void) viewdidload
{
[Superviewdidload];
Do no additional setup after loading the view, typically from a nib.
[Selfdoregister];
[Self doarray];
[Self doorder];
Self.tableView.dataSource =self;
Self.tableView.delegate =self;
[Self.tableviewregisterclass:[uitableviewcellclass] forcellreuseidentifier:@ "Cell"];
}
-(void) doregister{
[Sdwebimagemanager sharedmanager].imagedownloader.username =@ "HttpWatch";
[Sdwebimagemanager sharedmanager].imagedownloader.password =@ "httpwatch01";
}
-(void) doarray{
Self.array = [Nsarrayarraywithobjects:
@ "http://www.httpwatch.com/httpgallery/authentication/authenticatedimage/default.aspx?0.35786508303135633",// Requires HTTP auth, used to demo the NTLM Auth
@ "Http://assets.sbnation.com/assets/2512203/dogflops.gif",
@ "HTTP://WWW.IONCANNON.NET/WP-CONTENT/UPLOADS/2011/06/TEST2.WEBP",
@ "HTTP://WWW.IONCANNON.NET/WP-CONTENT/UPLOADS/2011/06/TEST9.WEBP",
@ "http://static2.dmcdn.net/static/video/656/177/44771656:jpeg_preview_small.jpg?20120509154705",
@ "http://static2.dmcdn.net/static/video/629/228/44822926:jpeg_preview_small.jpg?20120509181018",
@ "http://static2.dmcdn.net/static/video/116/367/44763611:jpeg_preview_small.jpg?20120509101749",
@ "http://static2.dmcdn.net/static/video/340/086/44680043:jpeg_preview_small.jpg?20120509180118",
@ "http://static2.dmcdn.net/static/video/666/645/43546666:jpeg_preview_small.jpg?20120412153140",
@ "http://static2.dmcdn.net/static/video/771/577/44775177:jpeg_preview_small.jpg?20120509183230",
@ "http://static2.dmcdn.net/static/video/810/508/44805018:jpeg_preview_small.jpg?20120508125339",
@ "http://static2.dmcdn.net/static/video/152/008/44800251:jpeg_preview_small.jpg?20120508103336",
@ "http://static2.dmcdn.net/static/video/694/741/35147496:jpeg_preview_small.jpg?20120508111445",
@ "http://static2.dmcdn.net/static/video/988/667/44766889:jpeg_preview_small.jpg?20120508130425",
@ "http://static2.dmcdn.net/static/video/282/467/44764282:jpeg_preview_small.jpg?20120507130637",
@ "http://static2.dmcdn.net/static/video/754/657/44756457:jpeg_preview_small.jpg?20120507093012",
@ "http://static2.dmcdn.net/static/video/831/107/44701138:jpeg_preview_small.jpg?20120506133917",
@ "http://static2.dmcdn.net/static/video/411/057/44750114:jpeg_preview_small.jpg?20120507014914",
@ "http://static2.dmcdn.net/static/video/894/547/44745498:jpeg_preview_small.jpg?20120509183004",
@ "http://static2.dmcdn.net/static/video/082/947/44749280:jpeg_preview_small.jpg?20120507015022",
@ "http://static2.dmcdn.net/static/video/833/347/44743338:jpeg_preview_small.jpg?20120509183004",
@ "http://static2.dmcdn.net/static/video/683/666/44666386:jpeg_preview_small.jpg?20120505111208",
@ "http://static2.dmcdn.net/static/video/595/946/44649595:jpeg_preview_small.jpg?20120507194104",
@ "http://static2.dmcdn.net/static/video/984/935/44539489:jpeg_preview_small.jpg?20120501184650",
@ "http://static2.dmcdn.net/static/video/440/416/44614044:jpeg_preview_small.jpg?20120505174152",
@ "http://static2.dmcdn.net/static/video/561/977/20779165:jpeg_preview_small.jpg?20120423161805",
@ "http://static2.dmcdn.net/static/video/104/546/44645401:jpeg_preview_small.jpg?20120507185246",
@ "http://static2.dmcdn.net/static/video/671/636/44636176:jpeg_preview_small.jpg?20120504021339",
@ "http://static2.dmcdn.net/static/video/142/746/44647241:jpeg_preview_small.jpg?20120504104451",
@ "http://static2.dmcdn.net/static/video/776/860/44068677:jpeg_preview_small.jpg?20120507185251",
@ "http://static2.dmcdn.net/static/video/892/748/51847298:jpeg_preview_small.jpg?20121105224514",
@ "http://static2.dmcdn.net/static/video/640/048/51840046:jpeg_preview_small.jpg?20121105214430",
@ "http://static2.dmcdn.net/static/video/153/648/51846351:jpeg_preview_small.jpg?20121105214426",
@ "http://static2.dmcdn.net/static/video/769/248/51842967:jpeg_preview_small.jpg?20121105214255",
@ "http://static2.dmcdn.net/static/video/720/448/51844027:jpeg_preview_small.jpg?20121105214248",
@ "http://static2.dmcdn.net/static/video/895/048/51840598:jpeg_preview_small.jpg?20121105214234",
@ "http://static2.dmcdn.net/static/video/893/348/51843398:jpeg_preview_small.jpg?20121105214157",
@ "http://static2.dmcdn.net/static/video/351/748/51847153:jpeg_preview_small.jpg?20121105214106",
@ "http://static2.dmcdn.net/static/video/364/648/51846463:jpeg_preview_small.jpg?20121105215005",
@ "http://static2.dmcdn.net/static/video/269/938/51839962:jpeg_preview_small.jpg?20121105214014",
NIL];
}
-(void) doorder{
[sdwebimagemanager.sharedmanager.imagedownloadersetvalue:@ "Sdwebimage Demo" forhttpheaderfield:@ "AppName"];
SDWebImageManager.sharedManager.imageDownloader.executionOrder =sdwebimagedownloaderlifoexecutionorder;
}
-(Ibaction) Doclean: (ID) Sender {
[SDWebImageManager.sharedManager.imageCacheclearMemory];
[SDWebImageManager.sharedManager.imageCacheclearDisk];
[Self.tableviewreloaddata];
}
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section;
{
return self.array.count;
}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexPath{
NSString * identifier = @ "cell";
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:identifier Forindexpath:indexpath];
[Cell.imageview Sd_setimagewithurl:[nsurlurlwithstring:[self.arrayobjectatindex:indexpath.row]]
Placeholderimage:nil
Options:indexPath.row ==0?
SDWEBIMAGEREFRESHCACHED:0];
return cell;
}
-(void) didreceivememorywarning
{
[Superdidreceivememorywarning];
Dispose of any of the can is recreated.
}
@end