您的位置:首页 > 产品设计 > UI/UE

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]);

}) ;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: