MBProgressHUD等待指示器

来源:互联网 发布:landesk远程控制软件 编辑:程序博客网 时间:2024/05/21 13:23

第三方的等待指示器,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方法代码如下,注意加粗部分:


view sourceprint?
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
原创粉丝点击