Dynamic cell heights of UITableView programmatically IOS7 in Swift
I ran into the problem since I decided to support IOS7, I used heightForRowAtIndexPath
to return UITableViewAutomaticDimension
which only works well with IOS8. and since UITableViewAutomaticDimension
doesn't work with IOS7 so I have to handle it manually. but there is no resource that can quickly help in this matter.
I am using a custom cell called "Card Cell":
class CardCell: UITableViewCell {
@IBOutlet var mainView: UIView!
@IBOutlet weak var text1: UILabel!
@IBOutlet weak var sharefb: UIButton!
}
so what if anyway it is possible to manually handle it in heightForRowAtIndexPath
using swift?
In iOS 7, you need to implement a protocol method UITableViewDelegate
and return the height of your cell.
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