我使用以下代码从 Web 服务下载 JSON。
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"my web service "]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
我根据这个 JSON 字符串创建我的用户界面,我需要在我的代码中添加一个进度条。我已经尝试了很多例子,但我无法让进度条正确显示。谁能告诉我如何使用进度条直到我的 View 加载完毕。这将是一个很大的帮助,谢谢。
最佳答案
如果您还没有决定使用哪种进度对话框,我推荐 MBProgressHUD:
https://github.com/jdg/MBProgressHUD
它相当易于使用,而且似乎正是您在这种情况下所需要的。如果您打算让请求同步,则在您的 View 生命周期中的所需时间点,例如viewDidLoad:
你可以有如下内容:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
// synchronously pull down the necessary JSON
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"my web service "]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
// perform the necessary view configuration you need to do based on this data
// .
// .
// .
[MBProgressHUD hideHUDForView:self.view animated:YES];
这将在您的配置进行时显示一个阻塞微调器,然后在该过程完成时将其清除。
关于ios - 添加ui进度 View ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20088860/