我正在用XIB的tableview单元创建一个tableview。
当我将tableview单元格与Tableview集成并运行时,它显示不完美,它显示了覆盖。

图片是

ios - Tableview单元格从底部被覆盖-LMLPHP

代码是

static NSString *cellIdentifier =@"DiscussionTableViewCell";

            DiscussionTableViewCell *cell = (DiscussionTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
            if (cell == nil) {

                NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"DiscussionTableViewCell" owner:self options:nil];
                cell = [topLevelObjects objectAtIndex:0];
                cell.selectionStyle=UITableViewCellSelectionStyleNone;
                // [cell.btnConnect addTarget:self action:@selector(btnUserConnectClick:) forControlEvents:UIControlEventTouchUpInside];
                // [cell.btnNotnow addTarget:self action:@selector(btnNotNowClick:) forControlEvents:UIControlEventTouchUpInside];
                 self.cellHeight  += cell.frame.size.height;
                NSLog(@"Cell height is %f",self.cellHeight);

最佳答案

请按照以下步骤操作:

  • 将标签numberOfLines属性更改为零

  • ios - Tableview单元格从底部被覆盖-LMLPHP
  • 向标签
  • 添加约束

    ios - Tableview单元格从底部被覆盖-LMLPHP
  • 更改高度约束关系

  • ios - Tableview单元格从底部被覆盖-LMLPHP
  • 实现这两个tableView委托方法
    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat{
          return 55
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat{
          return UITableViewAutomaticDimension
    }
    

  • 现在运行您的项目并检查。

    预期输出:

    ios - Tableview单元格从底部被覆盖-LMLPHP

    关于ios - Tableview单元格从底部被覆盖,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43108704/

    10-14 20:16
    查看更多