iOS tableView代码正常 但是cell不执行代理方法
搬砖魂 2019-03-18 07:08:36 附上代码
列表视图创建
- (UITableView *)tableview{
if (!_tableview) {
_tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, SPACING(0.8), SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
_tableview.delegate = self;
_tableview.dataSource = self;
_tableview.backgroundColor = [UIColor clearColor];
_tableview.userInteractionEnabled = YES;
[_tableview registerClass:[PersonInfoTableViewCell class] forCellReuseIdentifier:@"PersonInfoTableViewCell"];
TableViewFootEmpty(_tableview);
}
return _tableview;
}
cell生成代理方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
PersonInfoTableViewCell *cell = (PersonInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"PersonInfoTableViewCell"];
if (!cell) {
cell = [[PersonInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"PersonInfoTableViewCell"];
}
NSArray *array = self.dataArray[indexPath.section];
[cell configInfo:array[indexPath.row]];
return cell;
}
cell自定义
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.userInteractionEnabled = YES;
[self.contentView addSubview:self.nameLabel];
[self.contentView addSubview:self.arrow];
[self.contentView addSubview:self.contentLabel];
[self.contentView addSubview:self.headerIcon];
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
self.nameLabel.frame = CGRectMake(SPACING(2), (self.height - SPACING(1.5)) / 2., self.width / 4., SPACING(1.5));
self.arrow.frame = CGRectMake(self.width - SPACING(3.), (self.height - SPACING(1.6)) / 2., SPACING(1), SPACING(1.6));
self.contentLabel.frame = CGRectMake(self.nameLabel.rightX + SPACING(1), self.nameLabel.originY, self.arrow.originX - self.nameLabel.rightX - SPACING(2), SPACING(1.7));
self.headerIcon.frame = CGRectMake(self.arrow.originX - SPACING(5), (self.height - SPACING(4)) / 2., SPACING(4), SPACING(4));
self.line.frame = CGRectMake(self.nameLabel.originX, self.height - LINE_HEIGHT, SCREEN_WIDTH - self.nameLabel.originX, LINE_HEIGHT);
if (self.arrow.hidden) {
self.contentLabel.width = self.width - self.nameLabel.rightX - SPACING(3);
}
}