简体   繁体   中英

UITableViewCell Custom Height

Im trying to set a custom height for my UITableViewCell . In Xcode I have given it a custom height and added a UImageView subview and it looks fine. However at runtime the cell's height falls back to the default and my image is severely cropped.

I have setup the delegate to use a dynamic height and in Xcode have provided a custom height to the cell and my image is set to Aspect Fill. I'm not sure what else I am missing.

Here's my vc:

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 2
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    switch indexPath.section {
    case 0:
        return UITableViewAutomaticDimension
    default: ()
    return 50
    }
}

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    switch indexPath.section {
    case 0:
        return 300
    default: ()
    return 50
    }
}

Sure it's not a great and clear answer, but there might be problems with settings autolayouts. It's usuall difficult to provide all the data with layouts and constraints here, so may be it will be better for you to check up some material like this . And check up your code then.

我认为计分板在布局设置中存在一些问题,请根据此链接链接检查设置单元格

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM