- Download pictures using SD
#import "Uiimageview+webcache.h"
[Self. Hmimageview sd_setimagewithurl:url placeholderimage:nil options:0 progress:^ (Nsinteger receivedSize, NSInteger Expectedsize) {
Receivedsize received file size, total size of expectedsize file} completed:^ (UIImage *image, Nserror *error, Sdimagecachetype CacheType, Nsurl *imageurl) {}];
- Use SD to download gif
#import "Uiimage+gif.h"
Mode 1:
Self. Hmimageview.image = [UIImage sd_animatedgifnamed:@ "2"];
Mode 2
Get Picture Path
NSString *path = [[NSBundle mainbundle]pathforresource:@ "2.gif" oftype:nil];
Turn into binary
NSData *data = [NSData Datawithcontentsoffile:path];
Self. Hmimageview.image = [UIImage sd_animatedgifwithdata:data];
- Use the system's own cache, using the same way as the dictionary
The first step:
Global cache
@property (Nonatomic,strong) Nscache *cache;
Step Two:
-(Nscache *) cache{
if (_cache = = nil) {
_cache = [[Nscache alloc]init];
Set the number of caches
_cache.countlimit = 5
}
return _cache;
}
Step Three:
Access data
Storing data
[Self.cache setobject:[nsstring stringwithformat:@ "Hello%d", I] forkey:[nsstring stringwithformat:@ "haha%d", I]];
Fourth Step:
Reading data
NSLog (@ "%@", [Self.cache objectforkey:[nsstring stringwithformat:@ "haha%d", I]]);
Method called when the cache is removed
The first step is to abide by the agreement <NSCacheDelegate>
Called when the object is going to be removed
-(void) cache: (Nscache *) cache Willevictobject: (ID) obj
{
NSLog (@ "Willevict%@", obj);
}
4: Message loop: Runloop
There is a message loop inside each thread
Only the main thread's message loop is turned on by default, and the child thread's message loop is not turned on by default
5: The function of the message loop:
1: Can guarantee the application does not exit
2: Ability to handle input events
6. The mode of the input event must match the pattern of the message loop to be able to execute the code Nsdefaultrunloopmode of the input event, Nsrunloopcommonmodes (including the remaining two) Uitrackingrunloopmode
7. Set the mode of the message loop:
[[Nsrunloop Currentrunloop]addtimer:timer Formode:uitrackingrunloopmode];
8. Turn on the sub-thread: [[Nsrunloop Currentrunloop]addtimer:timer Formode:uitrackingrunloopmode];
9. Turn on child threads
[Self Performselector: @selector (Demo) Onthread:thread Withobject:nil Waituntildone:no];
10. The message loop (dead loop) of a child thread is not turned on by default and is manually turned on
[[Nsrunloop Currentrunloop]run];
Or, timing
[[Nsrunloop Currentrunloop]rununtildate:[nsdate datewithtimeintervalsincenow:3.0]];
Multithreading Knowledge points (V)