如何将 UIActivity 指示器添加到每个自定义 UItableviewCell



我是学习objective-c的新手。我想在从服务器显示图像期间向每个UITableViewCell添加UIActivity指示器,并在它们finishedloading.时隐藏它们

请帮我提供一些示例代码。

非常感谢。

请参考以下链接,

https://developer.apple.com/library/ios/samplecode/LazyTableImages/Introduction/Intro.html

https://github.com/rs/SDWebImage

编程方式创建的表视图的延迟称重传感器图像

http://www.markj.net/iphone-asynchronous-table-image/

http://www.hollance.com/2011/03/mhlazytableimages-efficiently-load-images-for-large-tables/#!

您可以在图像视图中添加活动指示器,并在图像开始从服务器加载时开始动画,当您从服务器加载实际图像时停止动画。请尝试以下代码

UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.center = imageView.center;// it will display in center of image view
[iamgeView addSubview:indicator];    
[indicator startAnimating]

当您有图像时调用[indicator stopAnimating]

在表视图单元格中停止动画:你最好设置位置

[imageView setImageWithURL:[NSURL URLWithString:imageURL]
               placeholderImage:[UIImage imageNamed:@"if any "]
                        success:^(UIImage *image) {
                            // remove animation
                          [indicator stopAnimating];
                          [indicator removeFromSuperview];
                        }
                        failure:^(NSError *error) {
                            // handle failed download
  }];

最新更新