У меня есть UITableViewCell
, который имеет 2 UIImageView
, определенный в файле xib. Теперь я пришел с идеей украсить ui, и я хотел бы изменить время выполнения UIImageView с UIActivityIndicatorView
, пока асинхронный ответ не вернется.замените UIImageView на UIActivityIndicatorView при загрузке изображения в UITableViewCell
К сожалению, UIActivityIndicatorView
не отображается вообще, просто полное изображение по окончании.
Вот relavant часть кода:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:myTableCellId];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
...
UIImageView *imageView = (UIImageView *)[cell viewWithTag:200];
...
imageView.image=nil; // reset image as it will be retrieved asychronously
UIActivityIndicatorView *loadingActivity = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[loadingActivity startAnimating];
loadingActivity.frame = imageView.frame;
UIView* parent = [imageView superview];
[parent addSubview:loadingActivity];
[parent bringSubviewToFront:loadingActivity];
[myObject callMyFunction:index completionBlock:^(UIImage *img) {
dispatch_async(dispatch_get_main_queue(), ^{
imageView.image=img;
[loadingActivity stopAnimating];
[loadingActivity removeFromSuperview];
//DLog(@"Got image for: %@", titleLabel.text);
});
}];
return cell;
}
Любые идеи, что не так?
Может быть, глупый вопрос с моей стороны, но есть ли белый спиннер на белом фоне? –
@Benoit да это помогает, добавьте в качестве ответа, чтобы его приняли !!! :) –