解析 + 网络请求

#import "YCViewController.h"
#import "YCmodel.h"
#import "YCTableViewCell.h"
#import "MBProgressHUD.h"
#import "MJRefresh.h"
#import "AFNetworking.h"
#import "MJExtension.h"
#import "UIImageView+WebCache.h"
#import "YanchuangViewController.h"
@interface YCViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView * tab;
//可变数组
@property(nonatomic,strong)NSMutableArray * aray;
@end

@implementation YCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.aray=[[NSMutableArray alloc]init];
   
    self.tab=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
   
    self.tab.delegate=self;
    self.tab.dataSource=self;
   
    [self.tab registerNib:[UINib nibWithNibName:@"LXTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.tab];
    [self AFNet];
   
}

-(void)AFNet{
   
    AFHTTPSessionManager * manager   = [AFHTTPSessionManager manager];
    [manager GET:@"http://c.m.163.com/nc/article/list/T1348648517839/0-20.html" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"%@",responseObject);
        NSArray *aray = responseObject[@"T1348648517839"];
        for(NSDictionary  * dic in aray){
            YCmodel * model  =[[YCmodel alloc ]init];
            [model setValuesForKeysWithDictionary:dic];
            [self.aray addObject:model];
           
        }
        //        dispatch_async(dispatch_get_main_queue(), ^{
        [self.tab reloadData];
       
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
       
    }];
   
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.aray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    YCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell  loadDataFromModel:self.aray[indexPath.row]];
   
    return cell;
   
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
    YanchuangViewController * first =[ YanchuangViewController new];
    YCmodel  * model = self.aray[indexPath.row];
    first.urstring = model.url;
    [self.navigationController pushViewController:first animated:YES];
   
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 150;
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、简介 <<UITableView(或简单地说,表视图)的一个实例是用于显示和编辑分层列出的信息的一种手段 <<...
    无邪8阅读 10,698评论 3 3
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,093评论 3 38
  • @interface Model : NSObject @property(nonatomic , strong)...
    老公123阅读 420评论 0 0
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 1,453评论 9 5
  • { 24、Sqlite数据库 1、存储大数据量,增删改查,常见管理系统:Oracle、MSSQLServer、DB...
    CYC666阅读 962评论 0 1