UIViewController的子类,且只有界面才有必要现实进度标示。然后在网络请求的开始和结束调用这个方法
1. 基于 UIViewController做扩展
#import
@implementation
void)showProgress
{
NSLog(@"=======showProgress=========");
MBProgressHUD *progressHUD = [[[MBProgressHUD alloc]initWithView:self.view] autorelease];
progressHUD.minSize = CGSizeMake(120, 120);
progressHUD.minShowTime = 0.3;
progressHUD.tag = 9999;
[self.view addSubview:progressHUD];
[self.view bringSubviewToFront:progressHUD];
progressHUD.layer.masksToBounds = YES;
progressHUD.layer.cornerRadius = 10.0;
progressHUD.labelText = @"加载中...";
mode = MBProgressHUDModeIndeterminate;
[progressHUD show:YES];
self.navigationController.navigationBar.userInteractionEnabled = NO;
}
void)hideProgress
{
NSLog(@"=======hideProgress=========");
UIView *progressHUD = [self.view viewWithTag:9999];
if
[progressHUD removeFromSuperview];
}
@end
2. 在网络请求开始地方调用方法
NetworkCenter中调用
在网络创建,加入请求队列之前调用,显示进度标示
if(responseDelegate && [responseDelegate respondsToSelector:@selector(showProgress)])
{
responseDelegate showProgress];
}
在网络请求成功、失败、网络异常调用,隐藏进度标示
if(responseDelegate && [responseDelegate respondsToSelector:@selector(hideProgress)])
{
responseDelegate hideProgress];
}