我从url加载一个大的plist文件,我必须等待几秒才能使用该应用程序。有一些解决方案吗?如何在后台加载? GCD
我需要什么?如何实施?
我的代码:
NSString *urlStr = [[NSString alloc]
initWithFormat:@"http://www.domain.com/data.xml"];
NSURL *url = [NSURL URLWithString:urlStr];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];
答案 0 :(得分:0)
您可以创建一个新线程来执行此操作 请检查以下
//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
});
}