//
// 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);
}