Search code examples
swiftios7storyboardcell

why custom table cell is always in default size


I set the custom cell Row Height to 132 in size inspector of storyboard. But my custom cell is always fixed to default row size and i can't see the different label's text properly for the short width of the row/cell. How can i overcome this issue ? Please see the images as reference. My problem with the 2nd prototype cell of image 1.png of upper link. Currently my simulator looks like 2.png, but it should be like 3.png in upper link of "images".


Solution

  • The object that is in charge of setting the height of every and each row of every section is the UITableViewDelegate

        // Variable height support
    
    optional func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    

    The same applies to the height of section headers, footers, etc...

    optional func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
    optional func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
    

    So implement those methods in your tableviewDelegate and that's it.