zoukankan      html  css  js  c++  java
  • ios 异步和多线程

    1

        //display&data
        _myview.view_searchbar.btn_back.hidden=true;
        [LSJsonHelper PrintLog:@"viewdidload"];
        [LSJsonHelper RequestHttp:gbl_urlindexcategory handle:^(NSDictionary *data) {
            [LSJsonHelper PrintLog:@"callback"];
            _data_category=[LSJsonHelper ConverJason2Model:data cc:[LSModel_VCategory_All class] isArray:YES];
            NSString *img1=[NSString stringWithFormat:@"%@%@",gbl_imgspath,_data_category[0].cg_pic];
            [LSJsonHelper PrintLog:@"before request img"];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [LSNSURL LoadImageForimg:img1 img:_myview.image_eat];
                [LSJsonHelper PrintLog:@"after set img to imagevie"];
            });
            
            [LSJsonHelper PrintLog:@"end this function"];
        }];
    2018-07-02 17:22:12.302 MyCity100[3014:82518] 2018-07-02 05:22:12:301.<NSThread: 0x7b771880>{number = 1, name = main} :viewdidload
    2018-07-02 17:22:12.309 MyCity100[3014:82518] 2018-07-02 05:22:12:309.<NSThread: 0x7b771880>{number = 1, name = main} :viewWillAppear
    2018-07-02 17:22:12.354 MyCity100[3014:82518] 2018-07-02 05:22:12:355.<NSThread: 0x7b771880>{number = 1, name = main} :viewDidAppear
    2018-07-02 17:22:12.431 MyCity100[3014:82573] 2018-07-02 05:22:12:431.<NSThread: 0x7c98ed90>{number = 3, name = (null)} :callback
    2018-07-02 17:22:12.436 MyCity100[3014:82573] 2018-07-02 05:22:12:436.<NSThread: 0x7c98ed90>{number = 3, name = (null)} :before request img
    2018-07-02 17:22:12.437 MyCity100[3014:82573] 2018-07-02 05:22:12:437.<NSThread: 0x7c98ed90>{number = 3, name = (null)} :end this function
    2018-07-02 17:22:15.616 MyCity100[3014:82518] 2018-07-02 05:22:15:616.<NSThread: 0x7b771880>{number = 1, name = main} :after set img to imagevie

    可以看到。异步网络请求后的回调函数是在子线程中执行。

    所以时间上一般页面执行完了显示函数,才会执行回调。

    更主要的是页面上的控件都是在主线程上创建的。基本所有语言都是要求由主线程进行刷新。

    oc 也不例外,所以编写主线程的回调函数。

     dispatch_async(dispatch_get_main_queue(), ^{
  • 相关阅读:
    Linux Apache Mysql PHP楷模设置配备摆设1
    谋划phpMyAdmin2.6以上版本数据乱码题目
    MYSQL到ORACLE法式迁徙的注意变乱
    关于MySQL中的mysqldump饬令的应用
    MySQL 5.0新特性教程 存储进程:第一讲
    Mysql 数据库的导入与导出
    Linux Apache Mysql PHP典范设置装备安排2
    MYSQL数据库初学者运用指南2
    图解MySQL数据库的铺排和操作3
    MySQL完成表中掏出随机数据
  • 原文地址:https://www.cnblogs.com/lsfv/p/9255113.html
Copyright © 2011-2022 走看看