我正致力于聊天。所以当我将图像发送给用户时。我需要像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再次在所有图像单元格中加载动画时。怎么解决?请帮帮我。
答案 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:不要只是复制/粘贴代码来检查它是否正常工作,掌握这个想法;)