iOS網路編程入門:MBProgressHUD等待指標

來源:互聯網
上載者:User

第三方的等待指標,MBProgressHUD就是第三方提供的等待指標架構。下面是MBProgressHUD提供的等待指標樣式,它們基 本可以分為:未知結束時間和已知結束時間兩大類等待指標,在MBProgressHUD中可以為等待指標添加標籤和詳細標籤

MBProgressHUD的下載地址是https://github.com/matej/MBProgressHUD,我們將下載的源 檔案中的MBProgressHUD.h和MBProgressHUD.m拷貝到自己的工程中,MBProgressHUD依賴的架構 有:Foundation.framework、UIKit.framework和CoreGraphics.framework,我們需要將這些架構添 加到工程中。

我們為應用添加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(@”請求完成…”);      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];      }

本文出自 “關東升” 部落格,請務必保留此出處http://2009315319.blog.51cto.com/701759/1174465

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.