作為一個(gè)渣渣程序猿,遇到有不懂的,肯定要查,問(wèn),然后再記錄一遍,不軟會(huì)忘的。
最近在做公司的項(xiàng)目,有用到HUD,當(dāng)你點(diǎn)擊的時(shí)候,進(jìn)行跳轉(zhuǎn),并請(qǐng)求數(shù)據(jù),顯示一個(gè)正在加載的轉(zhuǎn)圈的HUD,當(dāng)數(shù)據(jù)請(qǐng)求完成之后,刷新界面,移除HUD。
我的做法是在viewDidLoad
中,顯示HUD,進(jìn)行轉(zhuǎn)圈,提示用戶(hù)正在加載
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];
然后在數(shù)據(jù)請(qǐng)求成功的地方,因?yàn)槭褂昧藬?shù)據(jù)模型轉(zhuǎn)載數(shù)據(jù),所以可以通過(guò)判斷數(shù)據(jù)模型是否為空,來(lái)讓提示信息移除。
- (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];
}
}