这是我的问题,我正在构建一个带有一些来自服务器的 JSON 返回的 iOS,在这里,没有问题,一切正常。
问题是当我运行程序时,需要很长时间才能将结果解析为NSMutableArray
:这是日志
2013-01-10 12:03:48.627 project[5917:907] <- time begin parser
2013-01-10 12:03:48.755 project[5917:907] <- time finish parser
2013-01-10 12:03:48.756 project[5917:907] <- time begin implement arrays
2013-01-10 12:03:58.522 project[5917:907] <- time finish implement array
如您所见,实现数组真的很长。
我知道我必须使用排队和大中央调度来使我的 UI 响应,但我不知道怎么做,你能帮我做吗?
这是我的viewDidLoad
方法
- (void)viewDidLoad
{
[super viewDidLoad];
if debug
NSLog(@"<- time begin parser");
endif
NSString *URLStr = @"http://myJsonFile.json";
NSDictionary *myDictwithReturn = [TOCJSONParser awesomeParserWithStringOfYourJSONFile:URLStr]; //really cool parser, i can put it on gitHub if you want
NSArray *speakersArray = [myDictwithReturn objectForKey:@"speakers"];
myArray = [[NSMutableArray alloc]init];
NSLog(@"<- time finish parser");
NSLog(@"<- time begin implement arrays");
for (NSDictionary *myDict in speakersArray) {
_nextSpeaker = [[TOCSpk alloc]init];
[_nextSpeaker setName:[myDict objectForKey:@"name"]];
[_nextSpeaker setBusiness:[myDict objectForKey:@"business"]];
[_nextSpeaker setDesc:[myDict objectForKey:@"desc"]];
[_nextSpeaker setTwitter:[NSURL URLWithString:[myDict objectForKey:@"twitter"]]];
[_nextSpeaker setPicture:[_nextSpeaker retrieveImageFromServer:[myDict objectForKey:@"picture"]]];
[myArray addObject:_nextSpeaker];
}
NSLog(@"<- time finish implement array");
}