Ios MBProgressHUD仅在操作完成时显示
我正在使用MBProgressHUD显示带有加载动画的弹出窗口,但我有一个问题。当我按下按钮时,执行进度指示器调用。这就是行动Ios MBProgressHUD仅在操作完成时显示,ios,xcode,mbprogresshud,Ios,Xcode,Mbprogresshud,我正在使用MBProgressHUD显示带有加载动画的弹出窗口,但我有一个问题。当我按下按钮时,执行进度指示器调用。这就是行动 - (IBAction)calendarioButtonPressed:(UIButton *)sender { MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud.mode = MBProgressHUDModeIndeterminate; hud.label
- (IBAction)calendarioButtonPressed:(UIButton *)sender {
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"Uploading";
[hud show:YES];
[self getCalendarioJson];
}
在getCalendarioJson中,我有这个
- (void) getCalendarioJson {
//LETTURA CALENDARIO - INIZIO
NSString *calLink = myLink;
NSData* responseData = [NSData dataWithContentsOfURL:[NSURL URLWithString:calLink]];
NSArray* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions error:nil];
NSDictionary *firstObject = [json objectAtIndex:0];
NSDictionary *cal = [firstObject objectForKey:@"output"];
variabiliGlobali.calendario = [[NSMutableArray alloc] init];
for (NSDictionary *dict in cal) {
[variabiliGlobali.calendario addObject: dict];
}
//LETTURA CALENDARIO - FINE
}
为什么加载弹出窗口仅在getCalendarioJson执行结束时出现?
这个按钮有一段。当我从目标视图返回时,我可以看到弹出窗口
什么是metter?如果我删除segue,我可以在getCalendarioJson执行结束时看到弹出窗口(因为没有segue)
提前感谢。您有一个方法
[self-getCalendarioJson]
但此方法在主线程中运行,主线程用于UI更新,当您下载数据或进行持续数秒的操作时,主线程将等待进行UI更新
要解决这种情况,请将该方法放在后台线程中,是否可以使用[self-performSelectorInBackground:@selector(getCalendarioJson)with-Object:nil]代码>来自
您应该设置进度值。您为该条设置了进度吗?该条的彩色部分(即50%)响应您发送给该条的“进度”值。因此,如果设置progressBar.progress=0.5,则progressBar的颜色将为50%。我用密码写了一个答案。
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = @"Loading";
[self doSomethingInBackgroundWithProgressCallback:^(float progress) {
hud.progress = progress; //Here you set the progress
} completionCallback:^{
[hud hide:YES];
}];