//重写初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self addSubview:self.img];
[self addSubview:self.la];
[self addSubview:self.subLa];
[self addSubview:self.timeLa];
}
return self;
}
//图片
- (UIImageView *)img{
if (!_img) {
_img=[[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 60, 60)];
_img.layer.cornerRadius=30;
_img.layer.masksToBounds=YES;
}
return _img;
}
//标题
- (UILabel *)la{
if (!_la) {
_la=[[UILabel alloc]initWithFrame:CGRectMake(70, 5, 80, 20)];
_la.font=[UIFont systemFontOfSize:15];
}
return _la;
}
//副标题
- (UILabel *)subLa{
if (!_subLa) {
_subLa=[[UILabel alloc]initWithFrame:CGRectMake(70, 30, 300, 20)];
_subLa.textColor=[UIColor lightGrayColor];
_subLa.font=[UIFont systemFontOfSize:12];
}
return _subLa;
}
{
NSArray *arr;
NSDictionary *dic;
UITableView *tv;
UIView *_headerView;
UIImageView *imagee;
}
tv=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
tv.delegate=self;
tv.dataSource=self;
//行高
tv.rowHeight=70;
tv.tableHeaderView = _headerView;
[self.view addSubview:tv];
NSString *path=[[NSBundle mainBundle]pathForResource:@"QQ.plist" ofType:nil];
//获取所有数据源
dic=[NSDictionary dictionaryWithContentsOfFile:path];
//获取所有的key
arr=[dic allKeys];
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellID=@"cellid";
MyTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cellID"];
if (!cell) {
cell=[[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
}
//获得商品名称 key
NSString *str=[arr objectAtIndex:indexPath.row];
//获得该商品对用的数组信息
NSArray *dataArr=[dic objectForKey:str];
cell.img.image=[UIImage imageNamed:[dataArr objectAtIndex:0]];
cell.la.text=[arr objectAtIndex:indexPath.row];
cell.subLa.text=dataArr[1];
cell.timeLa.text=dataArr[2];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
网友评论