创建Cell模型
.m文件
#import "TgCell.h"
#import "LHSTg.h"
@interface TgCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *titleView;
@property (weak, nonatomic) IBOutlet UILabel *priceView;
@property (weak, nonatomic) IBOutlet UILabel *buyCountView;
@end
@implementation TgCell
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
//绑定标识
static NSString *ID = @"tg";
TgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
//cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
//从xib中加载cell
cell = [[[NSBundle mainBundle] loadNibNamed:@"LHSTgCell" owner:nil options:nil] lastObject];
}
return cell;
}
- (void)setTg:(LHSTg *)tg
{
_tg = tg;
//图片
self.iconView.image = [UIImage imageNamed:tg.icon];
//标题
self.titleView.text = tg.title;
//价格
self.priceView.text = [NSString stringWithFormat:@"¥%@",tg.price];
//购买数
self.buyCountView.text = [NSString stringWithFormat:@"%@人已购买",tg.buyCount];
}
@end
体现封装思想