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

  • 相关阅读:
    paste DEMO合并文件
    diff 文件比较
    grep DEMO
    tr DEMO
    uniq DEMO
    sort DEMO
    定义提示符 PS1 PS4
    MAVEN修改localRepository不起作用
    java数组初始化
    oracle监听服务无法打开
  • 原文地址:https://www.cnblogs.com/linyawen/p/2576190.html
Copyright © 2011-2022 走看看