0
我正在使用GCD下載UITableView的標題圖像。使用GCD的UITableView標題圖像下載
當我使用dispatch_async
時,圖像完全不顯示,當我使用dispatch_sync
時,它仍然是同步下載。我該如何解決 ?
eventDetailsTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) style:UITableViewStyleGrouped];
eventDetailsTable.dataSource = self;
eventDetailsTable.delegate = self;
[self.view addSubview:eventDetailsTable];
NSString *headerImageUrl = [NSString stringWithFormat:@"%@%@", [currentEvent objectForKey:@"baseurl"], [currentEvent objectForKey:@"sessionimage"]];
NSURL *headerImageURL = [NSURL URLWithString:headerImageUrl];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSData *imageData = [[NSData alloc] initWithContentsOfURL:headerImageURL];
UIImage *headerImage = [UIImage imageWithData:imageData];
UIImageView *headerImageView = [[UIImageView alloc] initWithImage:headerImage];
eventDetailsTable.tableHeaderView = headerImageView;
});
我試過了。它可以在模擬器中工作,但只有50%的時間在設備上運行 –