您好,登录后才能下订单哦!
- (void)viewDidLoad {
[super viewDidLoad];
_imgView = [[UIImageView alloc]initWithFrame:self.view.bounds];
_imgView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:_imgView];
// Do any additional setup after loading the view, typically from a nib.
// //方法1
// NSThread *thread = [[NSThread alloc]initWithTarget:self selector:@selector(test) object:nil];
// [thread start];
//
// //方法2
// [self performSelectorInBackground:@selector(test) withObject:nil];
// //方法3
// [NSThread detachNewThreadSelector:@selector(test) toTarget:self withObject:nil];
// //方法4 NSOperationQueue是一个操作队列或者线程池
NSOperationQueue *queue = [[NSOperationQueue alloc]init];
// queue.maxConcurrentOperationCount = 1;
// [queue addOperationWithBlock:^{//往队列中添加一个操作
// [self test];
// }];
// //方法5 不要直接去创建NSOperation对象
NSInvocationOperation *opertion = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(test) object:nil];
// opertion.queuePriority = NSOperationQueuePriorityVeryLow;
//
// NSInvocationOperation *opertion2 = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(test1) object:nil];
// opertion2.queuePriority = NSOperationQueuePriorityVeryHigh;
//
//方法6
// ThreadOperation *threadOperation = [[ThreadOperation alloc]init];
// [queue addOperation:threadOperation];
[queue addOperation:opertion];
// [queue addOperation:opertion2];
// BOOL bool1 = [[NSThread currentThread]isMainThread];
// NSLog(@"bool1 is %d",bool1);
// for (int i = 0; i < 10; i ++) {
// NSLog(@"-----------------main%d",i);
// }
}
- (void)test{
@autoreleasepool {
// [NSThread sleepForTimeInterval:5];
// BOOL bool2 = [[NSThread currentThread]isMainThread];
// NSLog(@"bool2 is %d",bool2);
// for (int i = 0; i < 10; i ++) {
// NSLog(@"-----------------test%d",i);
// }
// [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(run:) userInfo:nil repeats:YES];
// NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(run:) userInfo:nil repeats:YES];
// [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
//
// [[NSRunLoop currentRunLoop]run];
/*
https://cache.yisu.com/upload/information/20200312/67/250146.jpg
*/
// NSLog(@"1");
NSString *imgUrl = @"https://cache.yisu.com/upload/information/20200312/67/250147.jpg";
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrl]];
// _imgView.p_w_picpath = [UIImage p_w_picpathWithData:data];
[self performSelectorOnMainThread:@selector(show:) withObject:data waitUntilDone:NO];
}
}
- (void)run:(NSTimer *)timer{
}
- (void)show:(NSData *)data{
_imgView.p_w_picpath = [UIImage p_w_picpathWithData:data];
}
//- (void)test1{
// //[NSThread sleepForTimeInterval:5];
// BOOL bool2 = [[NSThread currentThread]isMainThread];
// NSLog(@"bool2 is %d",bool2);
// for (int i = 0; i < 10; i ++) {
// NSLog(@"-----------------test111111%d",i);
// }
//}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。