1.plist
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"name" ofType:@"plist"];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
2.tableView的自定义cell
1??:cell.m
// 自定义cell的初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self p_setupView];
}
return self;
}
- (void)p_setupView{
self.myImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
// self.myImage.backgroundColor = [UIColor brownColor];
// 自定义cell把控件添加到cell的contentView上面
[self.contentView addSubview:_myImage];
self.nameLable = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.myImage.frame) + 10, CGRectGetMinY(self.myImage.frame), CGRectGetWidth(self.contentView.frame) - CGRectGetWidth(self.myImage.frame) - 30,CGRectGetHeight(self.myImage.frame))];
self.nameLable.backgroundColor = [UIColor brownColor];
[self.contentView addSubview:_nameLable];
}
// 当bounds发生改变 走一个方法
- (void)layoutSubviews{
self.nameLable.frame = CGRectMake(CGRectGetMaxX(self.myImage.frame) + 10, CGRectGetMinY(self.myImage.frame), CGRectGetWidth(self.contentView.frame) - CGRectGetWidth(self.myImage.frame) - 30, CGRectGetHeight(self.myImage.frame));
}
2??:controller.m
- (void)viewDidLoad {
[super viewDidLoad];
// 1 先注册
[self.tableView registerClass:[MyCell class] forCellReuseIdentifier:@"cell"];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// 用自定义cell
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.myImage.image = [UIImage imageNamed:@"1.png"];
cell.nameLable.text = @"宋慧乔";
cell.nameLable.font = [UIFont systemFontOfSize:20];
return cell;
}
3.cell - model
1??:
2??:
3??:
4??:
6??: