MBProgressHUD等待指示器

第三方的等待指示器,MBProgressHUD就是第三方提供的等待指示器框架。下面是MBProgressHUD提供的等待指示器样式,它们基 本可以分为:未知结束时间和已知结束时间两大类等待指示器,在MBProgressHUD中可以为等待指示器添加标签和详细标签

原文:http://www.it165.net/pro/html/201304/5349.html

 

910

 

MBProgressHUD的下载地址是https://github.com/matej/MBProgressHUD,我们将下载的源 文件中的MBProgressHUD.h和MBProgressHUD.m拷贝到自己的工程中,MBProgressHUD依赖的框架 有:Foundation.framework、UIKit.framework和CoreGraphics.framework,我们需要将这些框架添 加到工程中。

我们为应用添加MBProgressHUD等待指示器,修改主视图控制器MasterViewController.m的startRequest方法代码如下,注意加粗部分:


001. -(void)startRequest
002.  
003. {
004.  
005. //初始化MBProgressHUD
006.  
007. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
008.  
009. hud.mode = MBProgressHUDModeCustomView;
010.  
011. hud.labelText = @”Loading”;
012.  
013. NSString *strURL = [[NSString alloc]
014.  
015. initWithFormat:@”http://iosbook3/mynotes/webservice.php”];
016.  
017. NSURL *url = [NSURL URLWithString:[strURL URLEncodedString]];
018.  
019. NSString *post;
020.  
021. if (action == ACTION_QUERY) {//查询处理
022.  
023. post = [NSString stringWithFormat:@"email=%@&type=%@&action=%@",
024.  
025. @"<你的iosbook1.com用户邮箱>",@"JSON",@"query"];
026.  
027. else if (action == ACTION_REMOVE) {//删除处理
028.  
029. NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
030.  
031. NSMutableDictionary*  dict = self.listData[indexPath.row];
032.  
033. post = [NSString stringWithFormat:@"email=%@&type=%@&action=%@&id=%@",
034.  
035. @"<你的iosbook1.com用户邮箱>",@"JSON",@"remove",[dict objectForKey:@"ID"]];
036.  
037. }
038.  
039. NSData *postData  = [post dataUsingEncoding:NSUTF8StringEncoding];
040.  
041. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
042.  
043. [request setHTTPMethod:@"POST"];
044.  
045. [request setHTTPBody:postData];
046.  
047. NSURLConnection *connection = [[NSURLConnection alloc]
048.  
049. initWithRequest:request delegate:self];
050.  
051. if (connection) {
052.  
053. _datas = [NSMutableData new];
054.  
055. }
056.  
057. }
058.  
059. -(void) connection:(NSURLConnection *)connection didFailWithError: (NSError *)error {
060.  
061. NSLog(@”%@”,[error localizedDescription]);
062.  
063. [MBProgressHUD hideHUDForView:self.view animated:YES];
064.  
065. }
066.  
067.  
068.  
069. - (void) connectionDidFinishLoading: (NSURLConnection*) connection {
070.  
071. NSLog(@”请求完成…”);
072.  
073. NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:_datas
074.  
075. options:NSJSONReadingAllowFragments error:nil];
076.  
077. if (action == ACTION_QUERY) {//查询处理 www.it165.net
078.  
079. [self reloadView:dict];
080.  
081. else if (action == ACTION_REMOVE) {//删除处理
082.  
083. NSString *message = @”操作成功。”;
084.  
085. NSNumber *resultCodeObj = [dict objectForKey:@"ResultCode"];
086.  
087. if ([resultCodeObj integerValue] < 0) {
088.  
089. message = [resultCodeObj errorMessage];
090.  
091. }
092.  
093. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@”提示信息”
094.  
095. message:message
096.  
097. delegate:nil
098.  
099. cancelButtonTitle:@”OK”
100.  
101. otherButtonTitles: nil];
102.  
103. [alertView show];
104.  
105. //重新查询
106.  
107. action = ACTION_QUERY;
108.  
109. [self startRequest];
110.  
111. }
112.  
113. [MBProgressHUD hideHUDForView:self.view animated:YES];
114.  
115. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值