Я использую UITableView
и хочу отобразить UIImageView
с загруженным изображением из сети в заголовке раздела. Так что мой метод
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
возвращает следующее UIView
:
UIView * header = [UIView new];
header.frame = CGRectMake(0, 0, self.view.frame.size.width, 200);
header.backgroundColor = UIColor.clearColor;
UserDataModel * userData = [CoreDataService sharedInstance].userData;
UIImageView * userImageView = [UIImageView new];
userImageView.frame = CGRectMake(20, 20, self.view.frame.size.width * 0.3, self.view.frame.size.width * 0.3);
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: userData.photoPath]];
if (data == nil) {
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
userImageView.image = [UIImage imageWithData: data];
});
});
[header addSubview:userImageView];
return header;
И это работает только после прокрутки таблицы, я не могу понять, что я сделал не так. Пожалуйста, объясните мне, почему это неправильно и как это сделать правильно.
Благодаря.