• NSThread 多线程相关


    1.下面的代码,有2点需要注意,1>就是 就是thread:所传得参数,这里传得的是nsarray  当然也可以传其他的类型。2>
    [self performSelectorOnMainThread:@selector(update) withObject:nil waitUntilDone:YES]; 这个函数的作用是通知主线程进行一下操作,比如这里是更新btn 的title。主要的参数需要注意的是 waitUntilDone ,如果是YES  那就需要等到 update操作完之后才会执行NSLog(@"-------------ddddd-----------");以及以后的代码,如果设置为NO的话,那不需要等到update完成就会执行。



    NSArray * array = [NSArray arrayWithObjects:@"a",@"b",@"c", nil]; therad = [[NSThread alloc]initWithTarget:self selector:@selector(thread:) object:array]; [therad start]; -(void)update { [btn setTitle:@"bbbbb" forState:UIControlStateNormal]; for( int i = 0; i < 100; ++ i ) { NSLog(@"i:%d",i); } } -(void)thread:(NSArray *)array { for( int i = 0; i < 3; ++ i ) { sleep(1); NSLog(@"%@",[array objectAtIndex:i]); } [self performSelectorOnMainThread:@selector(update) withObject:nil waitUntilDone:YES]; NSLog(@"-------------ddddd-----------"); }
  • 相关阅读:
    QGIS 编译
    Ubuntu: 无法使用su命令
    win7 与 Ubuntu 16.04 文件传送
    OSGEarth编译
    GADL配置编译
    C++ 类对象和 指针的区别
    C++ Primer Plus 第六版笔记
    Windows下使用doxygen阅读和分析C/C++代码
    _MSC_VER详细介绍
    LUA学习之一 初次接触
  • 原文地址:https://www.cnblogs.com/rollrock/p/4311835.html
Copyright © 2020-2023  润新知