美文网首页
UITableview的一些记录

UITableview的一些记录

作者: 流星阁 | 来源:发表于2021-06-29 15:21 被阅读0次

1.预估高度情况下cell上文本框编辑时或结束时动态更新高度,且保持编辑状态

修改完子控件约束后调用如下更新

  [tableView beginUpdates];
  [tableView endUpdates];

2.刷新闪烁问题

[UIView performWithoutAnimation:^{
   //刷新界面
    [self.tableView reloadData];
 }];

3.cell 点击时contentview上子控件消失

1.cell大小问题
2.设置cell selectionStyle 为UITableViewCellSelectionStyleNone

4.cell 多个分区设置圆角

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    cell.backgroundColor = [UIColor clearColor];
    CGFloat radius = 8;
    CAShapeLayer *normalLayer = [[CAShapeLayer alloc] init];
    CAShapeLayer *selectLayer = [[CAShapeLayer alloc] init];

    NSInteger rowNumber = [tableView numberOfRowsInSection:indexPath.section];

    UIBezierPath *bezierPath = nil;
    if (rowNumber == 1) {
        bezierPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds
                                           byRoundingCorners:UIRectCornerAllCorners
                                                 cornerRadii:CGSizeMake(radius, radius)];
    } else {
        if (indexPath.row == 0) {
            bezierPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds
                                               byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                     cornerRadii:CGSizeMake(radius, radius)];
        } else if (indexPath.row == rowNumber - 1) {
            bezierPath = [UIBezierPath bezierPathWithRoundedRect:cell.bounds
                                               byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
                                                     cornerRadii:CGSizeMake(radius, radius)];
        } else {
            bezierPath = [UIBezierPath bezierPathWithRect:cell.bounds];
        }
    }

    normalLayer.path = bezierPath.CGPath;
    selectLayer.path = bezierPath.CGPath;

    UIView *normalBgView = [[UIView alloc] initWithFrame:cell.bounds];
    normalLayer.fillColor = [[UIColor whiteColor] CGColor];
    [normalBgView.layer insertSublayer:normalLayer atIndex:0];
    normalBgView.backgroundColor = [UIColor clearColor];
    cell.backgroundView = normalBgView;

    UIView *selectBgView = [[UIView alloc] initWithFrame:cell.bounds];
    selectLayer.fillColor = [[UIColor whiteColor] CGColor];
    [selectBgView.layer insertSublayer:selectLayer atIndex:0];
    selectBgView.backgroundColor = [UIColor clearColor];
    cell.selectedBackgroundView = selectBgView;
}

5.plain模式下sectionheader背景色清除问题

1.清除contentView的背景色后,调用reloadData还是会出来
2.设置一张背景透明的图片替换headerview.backgroundView即可

相关文章

网友评论

      本文标题:UITableview的一些记录

      本文链接:https://www.haomeiwen.com/subject/phqkultx.html