第三方的等待指示器,MBProgressHUD就是第三方提供的等待指示器框架。下面是MBProgressHUD提供的等待指示器樣式,它們基 本可以分為:未知結(jié)束時(shí)間和已知結(jié)束時(shí)間兩大類等待指示器,在MBProgressHUD中可以為等待指示器添加標(biāo)簽和詳細(xì)標(biāo)簽
10年積累的成都做網(wǎng)站、網(wǎng)站制作經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有新和免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
MBProgressHUD的下載地址是https://github.com/matej/MBProgressHUD,我們將下載的源 文件中的MBProgressHUD.h和MBProgressHUD.m拷貝到自己的工程中,MBProgressHUD依賴的框架 有:Foundation.framework、UIKit.framework和CoreGraphics.framework,我們需要將這些框架添 加到工程中。
我們?yōu)閼?yīng)用添加MBProgressHUD等待指示器,修改主視圖控制器MasterViewController.m的startRequest方法代碼如下,注意加粗部分:
- -(void)startRequest
- {
- //初始化MBProgressHUD
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeCustomView;
- hud.labelText = @”Loading”;
- NSString *strURL = [[NSString alloc]
- initWithFormat:@”http://iosbook3/mynotes/webservice.php”];
- NSURL *url = [NSURL URLWithString:[strURL URLEncodedString]];
- NSString *post;
- if (action == ACTION_QUERY) {//查詢處理
- post = [NSString stringWithFormat:@"email=%@&type=%@&action=%@",
- @"<你的iosbook1.com用戶郵箱>",@"JSON",@"query"];
- } else if (action == ACTION_REMOVE) {//刪除處理
- NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
- NSMutableDictionary* dict = self.listData[indexPath.row];
- post = [NSString stringWithFormat:@"email=%@&type=%@&action=%@&id=%@",
- @"<你的iosbook1.com用戶郵箱>",@"JSON",@"remove",[dict objectForKey:@"ID"]];
- }
- NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding];
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
- [request setHTTPMethod:@"POST"];
- [request setHTTPBody:postData];
- NSURLConnection *connection = [[NSURLConnection alloc]
- initWithRequest:request delegate:self];
- if (connection) {
- _datas = [NSMutableData new];
- }
- }
- -(void) connection:(NSURLConnection *)connection didFailWithError: (NSError *)error {
- NSLog(@”%@”,[error localizedDescription]);
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }
- - (void) connectionDidFinishLoading: (NSURLConnection*) connection {
- NSLog(@”請(qǐng)求完成…”);
- NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:_datas
- options:NSJSONReadingAllowFragments error:nil];
- if (action == ACTION_QUERY) {//查詢處理
- [self reloadView:dict];
- } else if (action == ACTION_REMOVE) {//刪除處理
- NSString *message = @”操作成功。”;
- NSNumber *resultCodeObj = [dict objectForKey:@"ResultCode"];
- if ([resultCodeObj integerValue] < 0) {
- message = [resultCodeObj errorMessage];
- }
- UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@”提示信息”
- message:message
- delegate:nil
- cancelButtonTitle:@”OK”
- otherButtonTitles: nil];
- [alertView show];
- //重新查詢
- action = ACTION_QUERY;
- [self startRequest];
- }
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- }
分享文章:iOS網(wǎng)絡(luò)編程-MBProgressHUD等待指示器
URL鏈接:http://aaarwkj.com/article36/pjcjsg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、網(wǎng)站排名、App設(shè)計(jì)、python、企業(yè)網(wǎng)站制作、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)