dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSError *error = nil;
NSURL *urlRequest = [NSURL URLWithString:[NSString stringWithFormat:@"...", URL]];
NSString *json = [NSString stringWithContentsOfURL:urlRequest
encoding:NSASCIIStringEncoding
error:&error];
JKParseOptionFlags options = JKParseOptionStrict;
NSDictionary *results = [json objectFromJSONStringWithParseOptions:options];
NSString *body = [[results objectForKey:@"item"] objectForKey:@"description"];
Article *article = [[Article alloc] initWithTitle:title URL:URL body:body];
[self.articles insertObject:article atIndex:0];
});
就在这之外,[self.tableView reloadData];
但如果我NSLog(@"%d", self.articles.count);
在那之后立即调用它,它会返回 0。为什么不添加它?如果我在该块中调用 NSLog 访问文章的 body 属性,它将打印它,因此该对象似乎被创建得很好。是的,这个方法确实被调用(通过 viewDidLoad)。