每次显示的图像加载器动画都出现在tableview中的图像上

时间:2016-04-16 09:51:06

标签: ios chat whatsapp mbprogresshud

我正致力于聊天。所以当我将图像发送给用户时。我需要像Whatsapp上传图像一样显示动画。所以我使用MBProgressHUD.it工作正常。但是当我滚动表视图时出现所有图像的动画。我在本节中写了这段代码cellForRowAtIndexPath

     angular.module('MovieFeederApp.services', [])
      .factory('rtAPIservice', function($http, $scope) {

        var rtAPI = {};

        rtAPI.getMoviesAll = function($scope.nameFilter) {
          return $http({
            method: 'JSONP', 
            url: 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?q='+ $scope.nameFilter +  '&page_limit=10&page=1&apikey=MyKey&callback=JSON_CALLBACK'
          });
        }
return rtAPI;
});

它工作正常。但是当我滚动我的tableview再次在所有图像单元格中加载动画时。怎么解决?请帮帮我。

1 个答案:

答案 0 :(得分:0)

npm install npm@latest

之外写下此内容
@interface ViewController

并在typedef NS_ENUM(NSUInteger, DownloadState) { DownloadStateStopped, DownloadStateStarted, DownloadStateCompleted, };

中保留一个实例
ViewController

设置它的初始值:

@property (assign, nonatomic) DownloadState downloadState;

现在修复-(void)viewDidLoad { // your code self.downloadState = DownloadStateStopped; }

cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.imageview animated:YES]; // Set the annular determinate mode to show task progress. hud.mode = MBProgressHUDModeAnnularDeterminate; hud.label.text = NSLocalizedString(@"Loading...", @"HUD loading title"); if (self.downloadState == DownloadStateStopped) { dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{ // Do something useful in the background and update the HUD periodically. [self doSomeWorkWithProgress]; dispatch_async(dispatch_get_main_queue(), ^{ [hud hideAnimated:YES]; }); }); } }

doSomeWorkWithProgress

p.s:不要只是复制/粘贴代码来检查它是否正常工作,掌握这个想法;)