MBProgressHUD依赖的框架:Foundation.framework、UIKit.framework、CoreGraphics.framework。
1>MBProgressHUD类中获取MBProgressHUD对象方法:
// 创建MBProgressHUD对象添加到View视图中,并显示等待指示器
+ (MBProgressHUD *)showHUDAddedTo:(UIView *)view animated:(BOOL )animated ;
// 从顶级视图的子视图中查找MBProgressHUD对象
+ (MBProgressHUD *)HUDForView:(UIView *)view;
2>MBProgressHUD中常用属性
mode:设定指示器显示的样式
labelText:设置等待指示器标签的内容
detailsLabelText:设置等待指示器详细标签内容
customView:设置自定义视图
- (void)startRequest
{
// 初始化MBProgressHUD
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo: self.view animated :YES];
hud.mode = MBProgressHUDModeCustomView;
hud.labelText = @"Loading...";
NSString *strUrl = [[NSString alloc] initWithFormat:@"http://iosbook3.com/service/mynotes/webservice.php? email=%@&type=%@&action=%@",@"ios_yaoxinchao@163.com",@"JSON",@"query"];
NSURL *url = [NSURL URLWithString:[strUrl URLEncodedString]];
__weak ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{ // 设置成功完成时回调的Block
NSData *data = [request responseData];
NSDictionary *resDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
。。。。
[MBProgressHUD hideHUDForView:self.view animated:YES];
}];
[request setFailedBlock:^{ // 设置失败时回调的Block
NSError *error = [request error];
NSLog(@"%@",[error localizedDescription]);
[MBProgressHUD hideHUDForView:self.view animated:YES];
}];
[request startAsynchronous];
}