无标题文章

//

//  ViewController.m

//  DOM解析

//

//  Created by  on 2018/8/9.

//  Copyright ? 2018年 . All rights reserved.

/*DOM是系统不支持的

 可以使用谷歌提供的GDateXMLNode

 步骤:

 1.引用类库libxml2

 2.build setting -> Header search Paths 下

 添加 :/usr/include/libxml2

 Other Linker Flags 下

 添加: -lxml2

 3.GDataXMLNode 是在MRC下写的, 要想在ARC环境下使用需要做一些操作

 build Prases下   搜索 GData 添加 -fno-objc-arc

 */

viewcontroller.m

[self GetAFNetWorking];

- (void)GetAFNetWorking{

AFHTTPSessionManager *manager=[[AFHTTPSessionManager alloc]init];

 //获取头条的接口以及key值

 [manager GET:@“http://c.m.163.com/nc/article/headline/T1348647853363/0-20.html" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {



 } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {

 NSLog(@"%@",responseObject);



 for (NSDictionary *dic in responseObject[self.KEY]) {

 BaseModel *model=[[BaseModel alloc] init];

 [model setValuesForKeysWithDictionary:dic];

 [self.arr addObject:model];

 }

 NSLog(@"%@",self.arr);

 [self.table reloadData];



 } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

 NSLog(@"%@",error);


 }];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

            //你自定义的单元格名字

 BaseTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];

 if (self.arr.count>0) {

 BaseModel *model=self.arr[indexPath.row];


 //实现model方法

 [cell LoadData:model];


 }

 return cell;

}

Basemodel.h

@property (nonatomic,strong)NSString *imgsrc,*digest, *ltitle , *url;

Basemodel.m

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{


}

BasetableviewCell.h

@property (weak, nonatomic) IBOutlet UIImageView *imgView;

@property (weak, nonatomic) IBOutlet UILabel *titleLab;

@property (weak, nonatomic) IBOutlet UILabel *detailLab;

- (void)LoadData:(BaseModel *)model;

BasetableviewCell.m

- (void)LoadData:(BaseModel *)model{


 self.titleLab.text=model.ltitle;

 self.imgView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURLURLWithString:model.imgsrc]]];

 self.detailLab.text=model.digest;

 NSLog(@"asdbasda%@",model.digest);


}

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

推荐阅读更多精彩内容

  • 转至元数据结尾创建: 董潇伟,最新修改于: 十二月 23, 2016 转至元数据起始第一章:isa和Class一....
    40c0490e5268阅读 1,767评论 0 9
  • 【2017年最新】☞ iOS面试题及答案 设计模式是什么? 你知道哪些设计模式,并简要叙述? 设计模式是一种编码经...
    紫色冰雨阅读 623评论 0 1
  • 仿微信评论回复(简易) _Comma[https://www.jianshu.com/u/0fe61ffab4c2...
    summerTa阅读 218评论 0 0
  • http://blog.csdn.net/david21984/article/details/57451917 ...
    紫色冰雨阅读 576评论 0 0
  • 五年级 刘福涵 事情是这样的,大休息时,我们都在写作业,不知是谁提了个倡议:“走,出发。”我问:“去哪...
    语子梅阅读 337评论 0 5