zoukankan      html  css  js  c++  java
  • performSelectorInBackground

    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的打印顺序每次都 不太一样,这个可能跟系统执行有关.

  • 相关阅读:
    逆元
    C++快读
    最长单调上升子序列(LIS) O(nlogn)求法
    【简●解】巴厘岛的雕塑
    【简●解】学校食堂
    【简●解】[HNOI2005]星际贸易
    差分约束系统小结
    【简•解】花园
    最小生成树小结
    概率及期望DP小结
  • 原文地址:https://www.cnblogs.com/linyawen/p/2576190.html
Copyright © 2011-2022 走看看