簡體   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