繁体   English   中英

表格视图单元格大小

[英]Table view cell size

我在目标C中使用Xcode。

(我认为)我成功创建了一个表格视图,并创建了一个包含所有连接的新单元格。 问题在于运行时单元的大小。 我创建了一个较大的单元格,带有2个标签(1个顶部和1个底部),只能看到顶部标签。 屏幕截图

抱歉,如果重新发布,没有找到解决方法,谢谢。

您还必须实现方法tableView:heightForRowAtIndexPath:并返回所需的高度。

您需要添加以下UITableView委托方法:

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

      // return the desired height of your cell
      return 80.0f;
}

您必须编辑单元格和tableview控制器的选项TableView OptionsCellView选项

请试试这个。 这可能对您有帮助

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
      CGSize constraintSize = {245.0, 20000}
      CGSize neededSize = [ yourText sizeWithFont:[UIfont systemFontOfSize:14.0f] constrainedToSize:constraintSize  lineBreakMode:UILineBreakModeCharacterWrap]
        if ( neededSize.height <= 18) 

          return 45
    else return neededSize.height + 45 
    //18 is the size of your text with the requested font    (systemFontOfSize 14). if you change fonts you have a different number to use  
    // 45 is what is required to have a nice cell as the neededSize.height is the "text"'s height only
    //not the cell.

}

使用自定义TableView单元格

方法 在此处输入图片说明

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 105;
}

在tableViewdelegate(假设使用自动布局)中尝试一下:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
   return UITableViewAutomaticDimension;

}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
   return UITableViewAutomaticDimension;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM