GCD使用(一)执行与UI有关的操作
2014-01-09 11:00
417 查看
1。使用GCD时,与UI有关的操作只能放在主线程中进行
dispatch_get_main_queue,
dispatch_async ( dispatch_queue_t queue, dispatch_block_t block) 异步执行,参数:操作队列,执行块
dispatch_async_f ( dispatch_queue_t queue,void *context,dispatch_function_t work) 异步执行,参数:操作队列,传入C函数的参数,执行C函数
e.g.
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^(void) {
UIAlertView *alertView =[[UIAlertView alloc] initWithTitle:@"GCD" message:@"GCD is amazing!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[ alertView show];
NSLog(@"Current thread = %@", [NSThread currentThread]); //此处的操作均是在主线程中进行
NSLog(@"Main thread = %@", [NSThread mainThread]);
}) ;
dispatch_get_main_queue,
dispatch_async ( dispatch_queue_t queue, dispatch_block_t block) 异步执行,参数:操作队列,执行块
dispatch_async_f ( dispatch_queue_t queue,void *context,dispatch_function_t work) 异步执行,参数:操作队列,传入C函数的参数,执行C函数
e.g.
dispatch_queue_t mainQueue = dispatch_get_main_queue();
dispatch_async(mainQueue, ^(void) {
UIAlertView *alertView =[[UIAlertView alloc] initWithTitle:@"GCD" message:@"GCD is amazing!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[ alertView show];
NSLog(@"Current thread = %@", [NSThread currentThread]); //此处的操作均是在主线程中进行
NSLog(@"Main thread = %@", [NSThread mainThread]);
}) ;
相关文章推荐
- IOS开发(60)之使用GCD执行UI操作
- GCD使用(二)执行与UI无关的操作
- Android中使用Handler和异步任务(AsyncTack)来为UI线程执行费时操作
- Android中使用Handler和异步任务(AsyncTack)来为UI线程执行费时操作
- GCD使用(三)执行延时操作
- ios开发--GCD使用介绍:4-延迟执行操作
- 使用Activity类的runOnUiThread执行线程更新UI操作
- ios使用GCD来执行同步或异步串行、并行操作。
- GCD使用(四)操作只执行一次
- 使用GCD的方式来下载图片(耗时操作: 子线程执行)
- 使用sql语句建立与删除链接服务器及执行数据库操作
- "执行SQL语句时出现问题操作必须使用一个可更新的查询"错误的解决方法
- jetty->请求的操作无法在使用用户映射区域打开的文件上执行
- LINUX下使用Shell自动监控tomcat并且执行重启操作
- [Grails]使用Grails的Console执行简单的CRUD操作
- 有关采用Filter实现禁用缓存和使用缓存操作实现与分析
- 初始化 Microsoft Visual SourceSafe 源代码管理提供程序时失败。您无法使用此提供程序执行源代码管理操作
- 使用expect工具ssh登录远程服务器并执行命令操作
- IOS开发(61)之GCD执行非UI的操作
- MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作