简体   繁体   English

表格视图单元格大小

[英]Table view cell size

I am using Xcode with objective C. 我在目标C中使用Xcode。

(I think) I successful create a table view and created a new cell with all connections. (我认为)我成功创建了一个表格视图,并创建了一个包含所有连接的新单元格。 The problem is the size of the cell in runtime. 问题在于运行时单元的大小。 I create a bigger cell, with 2 labels (1 top and 1 bottom), can only see the top label. 我创建了一个较大的单元格,带有2个标签(1个顶部和1个底部),只能看到顶部标签。 屏幕截图

Sorry if is repost, didn't find one solution, and thanks. 抱歉,如果重新发布,没有找到解决方法,谢谢。

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

You need to add this UITableView delegate method: 您需要添加以下UITableView委托方法:

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

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

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

Please try this one. 请试试这个。 It may be helpful to you 这可能对您有帮助

 - (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.

}

Use Custom TableView Cell 使用自定义TableView单元格

Method 方法 在此处输入图片说明

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

Try this in tableViewdelegate (assumed using autolayout) : 在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