????????????????????????
????1.????????????
????NSThread * thread=[[NSThread alloc] initWithTarget:self selector:@selector(_update) object:nil];
????2.?????????????
????[NSThread detachNewThreadSelector:@selector(_update) toTarget:self withObject:nil];
????3.?????????????
????[self performSelectorInBackground:@selector(_update) withObject:nil];
????4.?????????????
????NSOperationQueue *queue=[[NSOperationQueue alloc] init];
????[queue addOperationWithBlock:^{
????for(int i=0;i<50;i++){
????printf("????? ");
????}
????}];
????5.?????????????
//?????????????
NSOperationQueue * queue=[[NSOperationQueue alloc] init];
//???ò??????
[queue setMaxConcurrentOperationCount:2];
//??????????????????????
NSInvocationOperation * thread1=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_update1) object:nil];
NSInvocationOperation *thread2=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_update2) object:nil];
[thread1 setQueuePriority:NSOperationQueuePriorityVeryLow];
[thread2 setQueuePriority:NSOperationQueuePriorityVeryHigh];
[queue addOperation:thread1];
[queue addOperation:thread2];
?????????????????????????????
????1.???????
???????????????????????????????????????????????????????????????????????????????????UI??
????2.????·
????????UIImageView ?????????????????????
???????????
#import "UIImageView+thread.h"
@implementation UIImageView(load)
- (void) setImageWithUrl:(NSString *)url{
[self performSelectorInBackground:@selector(_loadImage:) withObject:url];
}
- (void) _loadImage:(NSString *)u{
@autoreleasepool {
NSURL *url=[NSURL URLWithString:u];
NSData *data=[NSData dataWithContentsOfURL:url];
UIImage *image=[UIImage imageWithData:data];
[self performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO];
}
}