tableView cell height… how to customize it?

后端 未结 4 787
一向
一向 2020-12-09 10:35

Is it possible to modify height of only one cell in a grouped table view?
I have a table view with 2 sections of 3 and 2 rows... I would change row height of the second

相关标签:
4条回答
  • 2020-12-09 10:49

    You can look at this method:

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

    In your case, the code should look like:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
       if (indexPath.section == 1 && indexPath.row == 1) {
          return SPECIAL_HEIGHT;
       }
       return NORMAL_HEIGHT;
    }
    

    You can look for more details about the method here

    0 讨论(0)
  • 2020-12-09 10:55

    Have a look at

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

    For the indexpath just check for which row and section and adjust the height accordingly

    0 讨论(0)
  • 2020-12-09 11:00

    You can implement the following method to return the height for the row at a given index path:

    http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html%23//apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath:

    0 讨论(0)
  • 2020-12-09 11:01

    In iOS 8 and above we can use the Dynamic Table View Cell Height.

    Using this feature UITableviewCell get its height from its content and We don't need to write heightForRowAtIndexPath

    All I have to do in viewDidLoad()

    tableView.estimatedRowHeight = 44.0;
    tableView.rowHeight = UITableViewAutomaticDimension;
    

    If cell contains uilabel. then apply constraints to uilabel

    Make sure you change Label --Lines-- to 0

    The cell will grow automatically with content of uilabel:

    0 讨论(0)
提交回复
热议问题