Custom Cell Row Height setting in storyboard is not responding

后端 未结 18 1966
名媛妹妹
名媛妹妹 2020-11-30 16:54

I am trying to adjust the cell height for one of the cells on my table view. I am adjusting the size from the \"row height\" setting inside the \"size inspector\" of the cel

相关标签:
18条回答
  • 2020-11-30 17:14

    Open the storyboard in the XML view and try to edit the rowHeight attribute of the wanted element.

    It worked for me when I tried to set custom rowHeight for my prototyped row. It's not working via inspector, but via XML it works.

    0 讨论(0)
  • 2020-11-30 17:14

    You can use prototype cells with a custom height, and then invoke cellForRowAtIndexPath: and return its frame.height.:.

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [self tableView:tableView
                        cellForRowAtIndexPath:indexPath];
        return cell.frame.size.height;
    }
    
    0 讨论(0)
  • 2020-11-30 17:14

    Given that I did not find any solution to this problem through Interface Builder, I decided to post a programmatic solution to the problem in Swift using two dynamic cells, even though the initial question asked for a solution through Interface Builder. Regardless I think it could be helpful for the Stack Overflow community:

        import UIKit
    
        enum SignInUpMenuTableViewControllerCellIdentifier: String {
           case BigButtonCell = "BigButtonCell"
           case LabelCell = "LabelCell"
        }
    
        class SignInUpMenuTableViewController: UITableViewController {
                let heightCache = [SignInUpMenuTableViewControllerCellIdentifier.BigButtonCell : CGFloat(50),
                                  SignInUpMenuTableViewControllerCellIdentifier.LabelCell : CGFloat(115)]
    
        private func cellIdentifierForIndexPath(indexPath: NSIndexPath) -> SignInUpMenuTableViewControllerCellIdentifier {
            if indexPath.row == 2 {
                return SignInUpMenuTableViewControllerCellIdentifier.LabelCell
            } else {
                return SignInUpMenuTableViewControllerCellIdentifier.BigButtonCell
            }
        }
    
       override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
           return self.heightCache[self.cellIdentifierForIndexPath(indexPath)]!
       }
    
       ...
    
      }
    
    0 讨论(0)
  • 2020-11-30 17:15

    There are actually two places where you need to change to row height, first the cell (you already did change that) and now select the Table View and check the Size Inspector

    0 讨论(0)
  • 2020-11-30 17:17

    If you use UITableViewController, implement this method:

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

    In the function of a row you can choose Height. For example,

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (indexPath.row == 0) {
           return 100;
        } 
        else {
           return 60;
        }
    }
    

    In this exemple, the first row height is 100 pixels, and the others are 60 pixels.

    I hope this one can help you.

    0 讨论(0)
  • 2020-11-30 17:18

    On dynamic cells, rowHeight set on the UITableView always overrides the individual cells' rowHeight.

    But on static cells, rowHeight set on individual cells can override UITableView's.

    Not sure if it's a bug, Apple might be intentionally doing this?

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