简体   繁体   中英

Dynamic UITableView Cell Heights Programmatically IOS7 in Swift

I've been facing the problem since i decided to support IOS7, i was using heightForRowAtIndexPath to return UITableViewAutomaticDimension which is working well only with IOS8. and since UITableViewAutomaticDimension doesn't work with IOS7 so i have to handle it manually. but there is no such resource to help in swift about this issue.

i am using custom cell called "Card Cell" :

class CardCell: UITableViewCell {

    @IBOutlet var mainView: UIView!
    @IBOutlet weak var text1: UILabel!
    @IBOutlet weak var sharefb: UIButton!

}

so if there is anyway to handle it in heightForRowAtIndexPath manually using swift ?

In iOS 7 you need to implement UITableViewDelegate protocol method and return your cell height.

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 100.0;
}

you need to add

self.automaticallyAdjustsScrollViewInsets = false

before these two lines

tableView.estimatedRowHeight = 50
tableView.cellHeight = UITableViewCellAutomaticDimension

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