我有一个方法可以构建一个包,将其发送到网络服务,取回一个包,打开它并返回一个 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/