zoukankan      html  css  js  c++  java
  • 多线程刷新

    JSON解析的网络请求中;

     //1.获取访问路径

       

        NSString *path=@"http://1.studyios.sinaapp.com/gyxy.php?a=qq";

        //2.封装URL

        NSURL *url=[NSURL URLWithString:path];

        //3.创建请求命令

        NSURLRequest *request=[NSURLRequest requestWithURL:url];

        //4.创建会话对象   通过单例方法实现的

        NSURLSession *session=[NSURLSession sharedSession];

        //5。实行会话任务 通过request请求  获取data对象

        NSURLSessionDataTask *task=[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

           //6、json 解析                                                                                                       

            NSArray *arrJson=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];

            NSLog(@"%@",arrJson);

        }];

    //    7、真正的执行任务

        [task resume];

     得到集合 arrJson;

    向把集合放在tableView上会显示不出来;这是在teibleView上是多线程请求需要用到主线程刷新数据

    修改后:

    //1.获取访问路径

       

        NSString *path=@"http://1.studyios.sinaapp.com/gyxy.php?a=qq";

        //2.封装URL

        NSURL *url=[NSURL URLWithString:path];

        //3.创建请求命令

        NSURLRequest *request=[NSURLRequest requestWithURL:url];

        //4.创建会话对象   通过单例方法实现的

        NSURLSession *session=[NSURLSession sharedSession];

        //5。实行会话任务 通过request请求  获取data对象

        NSURLSessionDataTask *task=[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

           //6、json 解析                                                                                                       

            NSArray *arrJson=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];

            NSLog(@"%@",arrJson);

        dispatch_async(dispatch_get_main_queue(), ^{
          [self.table reloadData];
        });

        }];

    //    7、真正的执行任务

        [task resume];

    这样就能在tableView上显示了。

  • 相关阅读:
    MSRA-TD5000数据集使用详解
    2017CS231n学习笔记——计算机视觉的概述
    函数式非凡的抽象能力
    或许是领域建模的真相
    SpringBoot+ActiveMq实现订阅模式(Topic)消息队列
    SpringBoot下Activemq自定义MessageConverter
    spring boot 2.0类找不到EmbeddedServletContainerInitializedEvent
    Error creating bean with name 'org.apache.cxf.spring.boot.autoconfigure.CxfAutoConfiguration
    Intellij IDEA使用 lambda表达式报错-source1.5中不支持lambda表达式
    SpringBoot--实战开发--commons-lang3(三十五)
  • 原文地址:https://www.cnblogs.com/wrzheng/p/5357104.html
Copyright © 2011-2022 走看看