[英]add ui progress view ios
我使用以下代碼從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字符串創建用戶界面,並且需要在代碼中添加進度條。 我已經嘗試了許多示例,但是無法正確顯示進度欄。 誰能告訴我如何使用進度條來加載我的視圖。 這將是很大的幫助,謝謝。
如果您尚未決定要使用哪種進度對話框,建議您使用MBProgressHUD:
https://github.com/jdg/MBProgressHUD
它相當容易使用,並且似乎正是這種情況下您所需要的。 如果您設置為使請求同步,則在視圖生命周期中的所需時間點,例如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];
在您進行配置時,這將顯示阻塞微調器,然后在該過程完成時將其清除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.