/**
* 设置TableViewCell每一行数据
*/
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WActiveCellVo *activeVo = self.activeCellVoMutableArray[indexPath.row];
//1.创建Cell
WActiveCell *cell = [WActiveCell cellWithTableView:tableView];
cell.activeCellVo = activeVo;
return cell;
}
自定义Cell
#import <UIKit/UIKit.h>
#import "WActiveCellVo.h"
@interface WActiveCell : UITableViewCell
/**
* 通过Tableview创建一个Cell
*/
+(instancetype)cellWithTableView:(UITableView *)tableView;
/**
* 活动首页数据模型
*/
@property (strong, nonatomic) WActiveCellVo *activeCellVo;
@end
#import "WActiveCell.h"
#import "UIImageView+WebCache.h"
@interface WActiveCell()
/**
* 活动背景图:异步加载
*/
@property (weak, nonatomic) UIImageView *activeIconView;
@property (weak, nonatomic) UILabel *activeTitleLbl;
@property (weak, nonatomic) UILabel *activeAddressLbl1;
@property (weak, nonatomic) UILabel *activeAddressLbl2;
@property (weak, nonatomic) UIImageView *activeTimeIconView;
@property (weak, nonatomic) UILabel *activeTimeLbl;
@property (weak, nonatomic) UIImageView *activeAddressIconView;
@end
@implementation WActiveCell
+(instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *ID = @"WActiveCellIdentify";
//从缓存池中取出
WActiveCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
//从xib中加载cell
//cell = [[[NSBundle mainBundle] loadNibNamed:@"WActiveCell" owner:nil options:nil] lastObject];
cell = [[ WActiveCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
//0.活动背景图片
UIImageView *activeIconView = [[UIImageView alloc]init];
self.activeIconView = activeIconView;
[self.contentView addSubview:activeIconView];
//1.活动标题
UILabel *activeTitleLbl = [[UILabel alloc]init];
activeTitleLbl.textColor = [UIColor whiteColor];
activeTitleLbl.font = [UIFont boldSystemFontOfSize:16];
self.activeTitleLbl = activeTitleLbl;
[self.contentView addSubview:activeTitleLbl];
//2.活动地点1
UILabel *activeAddressLbl1 = [[UILabel alloc]init];
activeAddressLbl1.textColor = [UIColor whiteColor];
activeAddressLbl1.font = [UIFont systemFontOfSize:14];
self.activeAddressLbl1 = activeAddressLbl1;
[self.contentView addSubview:activeAddressLbl1];
//3.1活动时间图标
UIImageView *activeTimeIconView = [[UIImageView alloc]init];
activeTimeIconView.image = [UIImage imageNamed:@"activities_clock"];
activeTimeIconView.contentMode = UIViewContentModeCenter;
self.activeTimeIconView = activeTimeIconView;
[self.contentView addSubview:activeTimeIconView];
//3.2活动时间
UILabel *activeTimeLbl = [[UILabel alloc]init];
activeTimeLbl.textColor = [ UIColor blueColor];
activeTimeLbl.font = [UIFont systemFontOfSize:12];
self.activeTimeLbl = activeTimeLbl;
[self.contentView addSubview:activeTimeLbl];
//4.1活动地点图标
UIImageView *activeAddressIconView = [[UIImageView alloc]init];
activeAddressIconView.image = [UIImage imageNamed:@"activities_location"];
activeAddressIconView.contentMode = UIViewContentModeCenter;
self.activeAddressIconView = activeAddressIconView;
[self.contentView addSubview:activeAddressIconView];
//4.2活动地点2
UILabel *activeAddressLbl2 = [[UILabel alloc]init];
activeAddressLbl2.textColor = [UIColor blueColor];
activeAddressLbl2.font = [UIFont systemFontOfSize:12];
self.activeAddressLbl2 = activeAddressLbl2;
[self.contentView addSubview:activeAddressLbl2];
}
return self;
}
-(void)setActiveCellVo:(WActiveCellVo *)activeCellVo
{
_activeCellVo = activeCellVo;
//1.设置数据
[self settingData];
//2.设置frame
[self settingFrame];
}
/**
* 根据数据模型设置Cell子控件显示
*/
-(void)settingData
{
}
/**
* 根据模型设置Cell内部子控件的大小
*/
-(void)settingFrame
{
}