@interface MyTableViewCell ()
{
//保存应用程序图标
UIImageView *_iconView;
//保存公司的名称
UILabel *_publishView;
//应用程序名称
UILabel *_nameView;
//保存价格
UILabel *_priceView;
//评分的人数
UILabel *_numRatingsView;
//评分的分数
UIView *_ratingView;
}
@end
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//1.创建应用图标
_iconView = [[UIImageView alloc]init];
_iconView.frame = CGRectMake(5, 5, 60, 60);
[self.contentView addSubview:_iconView];
//2.创建公司名称
_publishView = [[UILabel alloc]init];
_publishView.frame = CGRectMake(90, 5, 250, 20);
[self.contentView addSubview:_publishView];
//3.应用名称
_nameView = [[UILabel alloc]init];
_nameView.frame = CGRectMake(90, 30, 200, 25);
[self.contentView addSubview:_nameView];
//4.价格
_priceView = [[UILabel alloc]initWithFrame:CGRectMake(300, 30, 60, 25)];
[self.contentView addSubview:_priceView];
//5.评分分数
_ratingView = [[UIView alloc]initWithFrame:CGRectMake(90, 65, 100, 23)];
_ratingView.backgroundColor = [UIColor lightGrayColor];
[self.contentView addSubview:_ratingView];
//6.评分人数
_numRatingsView = [[UILabel alloc]initWithFrame:CGRectMake(200, 65, 100, 20)];
[self.contentView addSubview:_numRatingsView];
}
return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellID = @"cellID";
//创建自定义cell
MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
//设置要显示的内容
//1.对自定义cell的相关属性赋值数据
NSDictionary *dict = [self.arrayData objectAtIndex:indexPath.row];
cell.iconView.image = [UIImage imageNamed:[dict objectForKey:@"Icon"]];
cell.publishView.text = [dict objectForKey:@"Publisher"];
cell.priceView.text = [dict objectForKey:@"Price"];
cell.nameView.text = [dict objectForKey:@"Name"];
cell.numRatingsView.text = [[dict objectForKey:@"NumRatings"] stringValue];
return cell;
}