I am trying to calculate the tableView's content size height which has dynamic increasing cells. For that I am writing code as -
override func viewDidLoad()
{
super.viewDidLoad()
self.tableView.estimatedRowHeight = 150
self.tableView.rowHeight = UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! MostLikedTVCscnd
cell.image.image = imageArr[indexPath.row] as? UIImage
cell.aboutLbl.text = labelArr[indexPath.row] as? String
let contentSizeHeight = tableView.contentSize.height//But here I am not getting the proper height
return cell
}
I checked an answer in the question for calculating tableView content size - https://stackoverflow.com/a/17939938/5395919 which reads
Note for those for whom this isn't working -- tableView:estimatedHeightForRowAtIndexPath messes with contentSize, so you might have luck just by removing your implementation of it. – weienw
So is there any means in which I can get correct content size despite dynamic cell size?
You can use key value observing (KVO) to be notified whenever the table view's content size changes. This may or may not work for what you're trying to do. I'm just not clear on what you're looking to obtain, but I don't think it would be good to try to use that in cellForRowAtIndexPath.
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.