继承 RootViewController.h
#import <UIKit/UIKit.h> #import "AFNetworking.h" #import "IWAccount.h" #import "IWAccountTool.h" #import "MJExtension.h" @interface RootViewController : UIViewController @end
#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (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
主页继承封装
#import "RootViewController.h" @interface HomeViewController : RootViewController @end
#import "HomeViewController.h" #import "MBProgressHUD+MJ.h" @interface HomeViewController () @end @implementation HomeViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor orangeColor]; //网络请求 //2.00L6_1_D3zyz2E450dccc178VbKkdD //https://api.weibo.com/2/statuses/home_timeline.json?access_token=2.00L6_1_D3zyz2E450dccc178VbKkdD // 1.创建请求管理对象 AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; // 2.封装请求参数 NSMutableDictionary *params = [NSMutableDictionary dictionary]; params[@"access_token"] = [IWAccountTool account].access_token; // 3.发送请求 [mgr GET:@"https://api.weibo.com/2/statuses/home_timeline.json" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { // 将字典数组转为模型数组(里面放的就是IWStatus模型) //self.statuses = [IWStatus objectArrayWithKeyValuesArray:responseObject[@"statuses"]]; // 刷新表格 } failure:^(AFHTTPRequestOperation *operation, NSError *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
原文:http://www.cnblogs.com/coderMJL/p/4852352.html