我从 url 加载一个大的 plist 文件,我必须等待几秒钟才能使用该应用程序。有什么解决办法吗?如何在后台加载它?是GCD
我需要的?如何实施?
My code:
NSString *urlStr = [[NSString alloc]
initWithFormat:@"http://www.domain.com/data.xml"];
NSURL *url = [NSURL URLWithString:urlStr];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];
您可以创建一个新线程来执行此操作
请检查以下内容
//Create the thread
[NSThread detachNewThreadSelector:@selector(loadPList) toTarget:self withObject:nil];
- (void) loadPList
{
//Load the plist
NSString *urlStr = [[NSString alloc]
initWithFormat:@"http://www.domain.com/data.xml"];
NSURL *url = [NSURL URLWithString:urlStr];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];
//Update the ui
dispatch_async(dispatch_get_main_queue(), ^{
//Update UI if you have to
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)