簡體   English   中英

自動調整UITableViewCell的內部UITableView

[英]Auto-Size UITableViewCell's internal UITableView

如果有人能幫助我為我解決以下問題,我將感到非常高興。

我正在嘗試使用不同的動態單元格構建UITableViewController。 任何單元格都有不同的高度,因此我確實從UITableViewDelegate覆蓋了heightForRow並返回了UITableViewAutomaticDimension。

到那時,對於我已添加到UITableView的每個單元,一切正常,直到我嘗試添加以下附加的單元格Cell example

在運行時,將調用以下單元格的heightForRow,內部UITableView的高度為0,因為UITableViewAutomaticDimension不考慮其高度。

我的問題是,來自外部的heightForRow如何考慮具有不同動態行高的內部UITableView?

感謝幫助 :)

您可以使用UITableViewDelegate方法獲得高度支持

// Variable height support

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

您可以計算內部工作台高度並在此處返回:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
       // check if table view is the outertable view in case you have the same delegate
       // let customCellHeight = number of subCells * heightOfSubCell + padding;
    return customCellHeight;    
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM