1 #import <UIKit/UIKit.h> 2 #import "MBProgressHUD.h" 3 @interface SplashViewController : UIViewController<MBProgressHUDDelegate> 4 { 5 MBProgressHUD *HUD; 6 } 7 @property (strong, nonatomic) IBOutlet UILabel *beiJingTime;//UILabel:显示从网络获取到的北京时间,在此label显示出来 8 - (IBAction)btn_Press:(UIButton *)sender;//点击按钮从网络获取北京时间。 9 @end
class="brush:objc;gutter:true;">注意添加MBProgressHUDDelegate代理方法。2) 在SplashViewController.m文件,添加如下代码:
1 - (IBAction)btn_Press:(UIButton *)sender {//点击获取网络时间 2 HUD = [[MBProgressHUD alloc] initWithView:self.view];//注意,在SplashViewController.view中初始化 3 [self.view addSubview:HUD]; 4 HUD.delegate = self; 5 HUD.labelText = @"正在加载"; 6 HUD.detailsLabelText = @"加载中,请稍候。。。。"; 7 HUD.square = YES; 8 [HUD showWhileExecuting:@selector(getTimeFromWeb) onTarget:self withObject:nil animated:YES];//执行获取网络时间 9 } 10 -(void)getTimeFromWeb 11 { 12 beiJingTime.text = [AppService BeiJingTime]; 13 } 14 #pragma mark - 15 #pragma mark MBProgressHUDDelegate methods 16 17 - (void)hudWasHidden:(MBProgressHUD *)hud {//释放HUD 18 // Remove HUD from screen when the HUD was hidded 19 [HUD removeFromSuperview]; 20 HUD = nil; 21 }