• 加载订阅标签数据


    //  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
  • 相关阅读:
    FineReport---数据集
    FineReport----单元格元素(数据列、公式、斜线)
    FineReport---样式
    SQL-修改: 将日期修改为空NULL、修改为空的记录
    sql---字段类型转换,保留小数位数,取日期格式,sql获取当前时间,时间处理
    深入浅出Mqtt协议
    一文了解Redis
    RDBMS关系型数据库与HBase的对比
    Greedysky:C++ 建议用 nullptr 而不是 NULL
    Greedysky:C++11 新特性之强制类型转换static_cast
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/6556282.html
Copyright © 2020-2023  润新知