作为一个渣渣程序猿,遇到有不懂的,肯定要查,问,然后再记录一遍,不软会忘的。
最近在做公司的项目,有用到HUD,当你点击的时候,进行跳转,并请求数据,显示一个正在加载的转圈的HUD,当数据请求完成之后,刷新界面,移除HUD。
我的做法是在viewDidLoad
中,显示HUD,进行转圈,提示用户正在加载
static float progress = 0.0f;
progress = 0.0f;
[SVProgressHUD showProgress:0 status:@"loading"];
[self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.1f];
[SVProgressHUD setBackgroundLayerColor:[[UIColor blackColor] colorWithAlphaComponent:0.5]];
[SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeCustom];
然后在数据请求成功的地方,因为使用了数据模型转载数据,所以可以通过判断数据模型是否为空,来让提示信息移除。
- (void)increaseProgress {
progress += 0.05f;
[SVProgressHUD showProgress:progress status:@"Loading"];
if (self.myselfDetailModel == nil) {
[self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.1f];
}else{
[SVProgressHUD dismiss];
}
}