- http://daimajishu.iteye.com/blog/1085729
-
- NSLog( @"main thread begin..." );
- [self performSelectorInBackground: @selector(getImages) withObject: nil];
- NSLog( @"main thread end..." );
- - (void)getImages
- {
- NSLog( @"one thread begin..." );
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- NSString *str_url = @"http://avatar.csdn.net/2/5/4/3_iorchid.jpg";
- NSURL *url = [NSURL URLWithString: str_url];
- NSData *data = [NSData dataWithContentsOfURL: url];
- UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: data]];
- imageView.frame = CGRectMake(50, 200, 80, 40);
- imageView.layer.cornerRadius = 6;
- imageView.layer.masksToBounds = YES;
- [self.window addSubview: imageView];
- NSLog( @"one thread end..." );
- [pool release];
- }
- 刚开始写getImages函数的时候,提示autorelease pool …leak之类的错误,后来发现,其实子进程默认不建立autoreleasepool,还得手动建立才行.
- log的打印顺序每次都 不太一样,这个可能跟系统执行有关.
子线程在后台运行: performSelectorInBackground
最新推荐文章于 2023-08-09 20:55:18 发布