自定义cell
创建 xib 文件
拖线和创建model文件
导入文件
#import “dinyueViewController.h”
#import “dianyingTableViewCell.h”
#import “dianyingmodel.h”
#import “AFHTTPSessionManager.h”
#import “AFNetworking.h”
@interface dinyueViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tab;
@property(nonatomic,strong)NSMutableArray *array;
@end
@implementation dinyueViewController
-
(void)viewDidLoad {
[super viewDidLoad];self.view.backgroundColor=[UIColor whiteColor];
AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@“text/html”];
[manager GET:@“http://api.expoon.com/AppNews/getNewsList/type/1/p/1” parameters:nil headers:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {for (NSDictionary *dic in responseObject[@"data"]) { model文件名 dianyingmodel *model = [[dianyingmodel alloc]init]; [model setValuesForKeysWithDictionary:dic]; [self.array addObject:model]; } dispatch_async(dispatch_get_main_queue(), ^{ [self.tab reloadData]; });
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"///////////////%@",error);
}];_array=[NSMutableArray new];
_tab=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
_tab.dataSource=self;
_tab.delegate=self;
自定义就是在这多的一步 注册
[_tab registerNib:[UINib nibWithNibName:@“dianyingTableViewCell” bundle:nil] forCellReuseIdentifier:@“cell”];
[self.view addSubview:_tab];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _array.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ 也是和系统的差不多 改变
dianyingTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@“cell”];
if(cell==nil)
{
cell=[[dianyingTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@“cell”];
}
if(self.array>0)
{
_tab.rowHeight=160;
赋值 把东西放到数组
dianyingmodel *model=self.array[indexPath.row];
连接
cell.lab1.text=[NSString stringWithFormat:@“标题:%@”,model.news_title];
cell.lab2.text=[NSString stringWithFormat:@“浏览量是:%@”,model.news_id];
网络上的照片
cell.image.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:model.pic_url]]];
}
return cell;
}
@end