我需要点击一个button 变换成有三个button 的imageView,跳转界面,返回添加cell,最开始是使用段头段位的形式来实现,但是我发现,如果段头的话,可以获取到段头上的button 的点击事件,页可以确定那个button,但是点击button 变换imageView 无法确认具体哪一个,所以,全部换成cell 来实现,通过cell 的indexPath.row 的单双来确定每个cell 的高度以及cell的显示,如图
但是确定点击button 变换imageView这里还是费了一番心思,具体代码如下
- (void)headButtonClick:(UIButton *)button{
NSInteger btnTag = button.tag;
DLog(@"%ld",(long)btnTag);
// UITableViewCell *cell = (UITableViewCell *)[button superview];//获取cell
// NSIndexPath *indexPathAll = [_headTableView indexPathForCell:cell];//获取cell对应的section
// DLog(@"indexPath:--------%@",indexPathAll);
NSArray *cellArray = [_headTableView visibleCells];
NSMutableArray *cellAllArray = [NSMutableArray array];
for (int i = 0; i < [cellArray count]; i++) {
UITableViewCell *cell = cellArray[i];
if ([cell isKindOfClass:[ActivityPubHeadCell class]]) {
[cellAllArray addObject:cell];
}
}
//遍历整个tableview中可见的cell
for (ActivityPubHeadCell *headCell in cellAllArray){
DLog(@"%@",[_headTableView visibleCells])
if (headCell.imgBackView.tag == btnTag + 200){
headCell.imgBackView.hidden = NO;
headCell.addBtn.hidden = YES;
}
}
}
实现效果如下:
yeah,真的只想说一声终于···
原以为UITableViewHeaderFooterView 也有这个方法,或者用段头方式也可以这样实现,结果尝试了一下,事实证明我还是想多了···