zoukankan      html  css  js  c++  java
  • 4. iOS中常用演示方法以及利弊

    - (void)delay1
    {
        // 延迟执行不要用sleep,坏处:卡住当前线程
        [NSThread sleepForTimeInterval:3];
        NSLog(@"-----下载图片-----");
    }
    - (void)delay2
    {
        // 一旦定制好延迟任务后,不会卡主当前线程(延时任务在哪条线程执行取决于当前代码在何处调用)
        [self performSelector:@selector(download:) withObject:@"http://555.jpg" afterDelay:3];
    }
    - (void)delay3
    {
        // 3秒后回到主线程执行block中的代码
    //    dispatch_queue_t queue = dispatch_get_main_queue();
    //    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), queue, ^{
    //        NSLog(@"------task------%@", [NSThread currentThread]);
    //    });
        
        // 3秒后自动开启新线程 执行block中的代码(也就是说会帮你开启一条新的线程,延时一段时间之后执行block中的代码)
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), queue, ^{
            NSLog(@"------task------%@", [NSThread currentThread]);
        });
    }
  • 相关阅读:
    Python基础:28正则表达式
    Remove Duplicates from Sorted Array
    Reverse Nodes in k-Group
    Merge k Sorted Lists
    Generate Parentheses
    Container With Most Water
    Regular Expression Matching
    Median of Two Sorted Arrays
    sql 子查询
    linux安装服务器
  • 原文地址:https://www.cnblogs.com/chnyang/p/5361797.html
Copyright © 2011-2022 走看看