您的位置:首页 > 其它

ProgressHUD 的使用

2015-07-15 10:26 69 查看

一、主要方法简介:

// 网络请求开始之前,先给用户提示,网络正在加载中...
   [ProgressHUDshow:@"加载中..."Interaction:YES];

     // 取消风火轮旋转
     [ProgressHUD dismiss];

[ProgressHUD showSuccess:@"数据已经为您请求成功" Interaction:YES];

[ProgressHUD showError:@"大爷,你的网不好,你看毛线啊" Interaction:YES];


二、代码示例:

//
//  RootViewController.m
//  ProgressHUD_test
//
//

#import "RootViewController.h"
#import "AFHTTPRequestOperationManager.h"
#import "ProgressHUD.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // 网络请求开始之前,先给用户提示,网络正在加载中...
    [ProgressHUD show:@"加载中..." Interaction:YES];

    // 初始化 AFHTTPRequestOperationManager,不需要alloc
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    /*
     第一个参数:接口地址
     第二个参数:传递参数时要用到,GET请求不需要传递参数,所以此处写nil就可以,当POST请求的时候,需要在接口后边拼接参数,把参数以 key : Value 的形式封装到字典里,AFNetworking为自动给为我们把需要传递的参数拼接到我们的接口后边。
     第三个参数:是网络请求成功的回调方法,responseObject 参数是 请求到得 JSON 数据
     第四个参数:是网络请求失败的时候的回调方法,error 参数,是网络请求失败的信息
     */
    [manager GET:@"http://api.smzdm.com/v1/util/banner?s=55691368cf612709254&type=home&v=5.6.1&f=iphone" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

        [ProgressHUD showSuccess:@"数据已经为您请求成功" Interaction:YES];
        // 取消风火轮旋转
//        [ProgressHUD dismiss];

        NSLog( @"%@", responseObject ) ;
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [ProgressHUD showError:@"大爷,你的网不好,你看毛线啊" Interaction:YES];

        NSLog( @"error:%@", error ) ;
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


三、注意事项:

这个第三方只能用在 view 上
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: