在我的代码中,我称之为
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (responseData != nil) {
NSError *error = nil;
NSArray *dataSource = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error];
[self.ticker1 loadData:dataSource];
} else {
NSLog(@"Error requesting timeline %@ with user info %@.", error, error.userInfo);
}
}];
在loadData:
我这样做的方法中
NSDictionary *dict = [dataSource objectAtIndex:0];
_label.text = [dict objectForKey:@"text"];
dispatch_queue_t queue = dispatch_queue_create("com.test.ios.task", NULL);
dispatch_queue_t main = dispatch_get_main_queue();
dispatch_async(queue, ^{
NSURL *imageURL = [NSURL URLWithString:[[dict objectForKey:@"user"] objectForKey:@"profile_image_url"]];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
dispatch_async(main, ^{
_image.image = [UIImage imageWithData:imageData];
});
});
dispatch_release(queue);
问题是我在主队列加载的图像比_label.text
设置的要快得多。它在大约 4-5 秒的长时间延迟后被设置。我想知道为什么会这样。是因为main queue
没有发布还是那条线上的东西?