zoukankan      html  css  js  c++  java
  • iOS开发多线程篇—GCD的常见用法

     1 //
     2 //  YYViewController.m
     3 //  01-GCD的常见使用(延迟执行)
     4 //
     5 //  Created by apple on 14-6-25.
     6 //  Copyright (c) 2014年 itcase. All rights reserved.
     7 //
     8 
     9 #import "YYViewController.h"
    10 
    11 @interface YYViewController ()
    12 
    13 @end
    14 
    15 @implementation YYViewController
    16 
    17 - (void)viewDidLoad
    18 {
    19     [super viewDidLoad];
    20     NSLog(@"打印线程----%@",[NSThread currentThread]);
    21     //延迟执行
    22     //第一种方法:延迟3秒钟调用run函数
    23     [self performSelector:@selector(run) withObject:nil afterDelay:2.0];
    24     
    25 }
    26 -(void)run
    27 {
    28     NSLog(@"延迟执行----%@",[NSThread currentThread]);
    29 }
    30 
    31 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    32 {
    33     //在异步函数中执行
    34     dispatch_queue_t queue = dispatch_queue_create("wendingding", 0);
    35     
    36     dispatch_sync(queue, ^{
    37         [self performSelector:@selector(test) withObject:nil afterDelay:1.0];
    38     });
    39     NSLog(@"异步函数");
    40 }
    41 -(void)test
    42 {
    43     NSLog(@"异步函数中延迟执行----%@",[NSThread currentThread]);
    44 }
    45 @end
  • 相关阅读:
    获取客户及登录IP(Java)
    js初步
    数组方法
    BOM ;浏览器对象模型
    js事件
    EventListener()
    JS面向对象
    正则表达式
    -CSS盒模型和float
    EventListener()
  • 原文地址:https://www.cnblogs.com/iosblogx/p/4474505.html
Copyright © 2011-2022 走看看