zoukankan      html  css  js  c++  java
  • 加载订阅标签数据

    //  XMGSubTagViewController.m
    
    
    #import "XMGSubTagViewController.h"
    #import <AFNetworking/AFNetworking.h>
    #import "XMGSubTagItem.h"
    #import <MJExtension/MJExtension.h>
    
    @interface XMGSubTagViewController ()
    
    @property (nonatomic, strong) NSArray *subTags;
    
    @end
    
    @implementation XMGSubTagViewController
    // 接口文档: 请求url(基本url+请求参数) 请求方式
    - (void)viewDidLoad {
        [super viewDidLoad];
        
       // 展示标签数据 -> 请求数据(接口文档) -> 解析数据(写成Plist)(image_list,sub_number,theme_name) -> 设计模型 -> 字典转模型 -> 展示数据
        [self loadData];
    }
    
    #pragma mark - 请求数据
    - (void)loadData
    {
        // 1.创建请求会话管理者
        AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
        // 2.拼接参数
        NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
        parameters[@"a"] = @"tag_recommend";
        parameters[@"action"] = @"sub";
        parameters[@"c"] = @"topic";
        
        // 3.发送请求
        [mgr GET:@"http://api.budejie.com/api/api_open.php" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSArray *  _Nullable responseObject) {
    //        [responseObject writeToFile:@"/Users/xiaomage/Desktop/课堂共享/11大神班上课资料/08-项目/0315/代码/05-订阅标签/tag.plist" atomically:YES];
    //        NSLog(@"%@",responseObject);
            // 字典数组转换模型数组
           _subTags = [XMGSubTagItem mj_objectArrayWithKeyValuesArray:responseObject];
            
            // 刷新表格
            [self.tableView reloadData];
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];
        
    }
    
    #pragma mark - Table view data source
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return self.subTags.count;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *ID = @"cell";
        // 自定义cell
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        }
        // 获取模型
        XMGSubTagItem *item = self.subTags[indexPath.row];
        cell.textLabel.text = item.theme_name;
        
        return cell;
    }
    
    @end
  • 相关阅读:
    UVA 10970 Big Chocolate
    HBuilder 安装uviewui2.0
    域名访问配置支持ipv6
    SSIS学习视频(SQL Server 2008)
    碰到MySQL无法启动1067错误问题
    对存储过程进行加密和解密(SQL 2008/SQL 2012)
    脚本文件比较工具WinMerge
    通过SQL绘制杨辉三角
    通用分页存储过程(SQL Server 2005)
    重新组织和重新生成索引sp_RefreshIndex
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6556282.html
Copyright © 2011-2022 走看看