ios - 在后台线程上解析来自 WebService 的 JSON 数据

标签 ios multithreading background

我有一个方法可以构建一个包,将其发送到网络服务,取回一个包,打开它并返回一个 nsdictionary。如何在后台队列上调用它,以便在请求数据时显示 HUD?

最佳答案

您可以像下面这样分离一个新线程

- (void) fetchData
{
     //Show Hud

    //Start thread
    [NSThread detachNewThreadSelector:@selector(getDataThreaded) 
    toTarget:self  
    withObject:nil];
}

- (void) getDataThreaded
{    
   //Start Fetching data

   //Hide hud from main UI thread
   dispatch_async(dispatch_get_main_queue(), ^{
        //Update UI if you have to
        //Hide Hud
    });
}

关于ios - 在后台线程上解析来自 WebService 的 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10920080/

相关文章:

objective-c - 显示预加载的搜索结果?

iOS 8 - 通知在新的 Ad Hoc 版本中停止工作

Android:更改 fragment 的背景颜色

iphone - iOS 应用程序如何在后台无限期地保持 TCP 连接?

html - 幻灯片放映/更改背景图片

ios - django-allauth 中多个设备的访问 token 授权

ios - 根据属性值更改颜色

c++ - 多线程中的套接字

c++ - 释放在不同同步上下文中使用的类成员

python - 在 Python 3 中发送多个 HTTP 请求的最佳方式是什么?