You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My problem its that (I copy the exact constraints) when I load information, like 2-3 lines it only appear the first or second line and the other line I need to scroll until the cell its outside the screen and bring it inside again and it comes with the other line. I hop eI explain my self.
I don't think I have enough information to try and help. Did you compare your code to the code of this sample project on GitHub?
You'll probably need to share your entire project (or a sample project that illustrates the issues your seeing) if you would like more help in debugging.
90% of the issues people have with this is that their constraints are not correct, even though they think they are. I recommend double and triple checking that you have all the constraints you need -- it sounds like you could have an ambiguous layout issue.
Hi @smileyborg , any email? also I copy the cell you have, exactly the same. And the cells resize perfectly but I need to reload the cell (put it off screen and put it again on screen)
You can email tfox [at] smileyborg (dot) com. The issue could be related to the preferredMaxLayoutWidth of multi-line labels - not being set the first layout pass.
@smileyborg. With that modification it renders the height fine, but the distance between the label1 and label 2 (like your example) differ. When I hide and show the cell it appear with the exact position. Also the height of the cell changes
Interesting, I'm not sure exactly what's going on. But it seems to suggest there are bugs with Apple's implementation of self sizing cells particularly when loading from a Storyboard/nib. You may wish to switch to implementing it in code (as in this example project), as it seems to be more reliable.
The problem with cells being loaded from a storyboard is that the cell's width does not initially correspond to the tableView's width (which affects the label's preferredMaxLayoutWidth). Reloading simply reuses a cell which at that point has the proper frame size.
Cells instantiated in code are created with the right dimensions from the start, so they appear correct at the first load.
The problem with cells being loaded from a storyboard is that the cell's width does not initially correspond to the tableView's width (which affects the label's preferredMaxLayoutWidth). Reloading simply reuses a cell which at that point has the proper frame size.
Cells instantiated in code are created with the right dimensions from the start, so they appear correct at the first load.
—
Reply to this email directly or view it on GitHub.
@PetahChristian You're probably right. But if so, this is definitely a bug on Apple's side. If you can confirm your hypothesis and still see issues with the latest iOS version I would definitely file a radar.
By the way, not sure if anyone here had made progress on this issue. But I ran into something (potentially) similar recently, and found a workaround that may be helpful...see my comment at the bottom of this article:
If you're having row height issues on iOS 8.0 or 8.1, where your cells are sized incorrectly, after you initially call [tableView reloadData] to populate the table with cells, add the following:
Forcing a layout pass on the table view and then doing a 2nd reloadData caused the cells to be sized correctly in my case (some debugging clearly indicated that the issue was with the table view's internal height calculation, not with the cell). This workaround also is invisible to the user, since it all happens synchronously before a redraw.
Reacted by Hamid Reza Ansari, BalintDezso, rolflocher and Deblina Always
Just call self.tableView.reloadDataWithAutoSizingCellWorkAround() instead of self.tableView.reloadData()
Reacted by Wang Shudao, Tony Lam, raisalcalicut, Erwin Gaitan, Jack Sheridan, Stacey D, Adam Pietrafesa, dhana, Trung Hoang Dang, johnrajahkkd and 15 more
Reacted by SwiftyFlow and Davis Koh
Reacted by dhana, James Mallison, Kirils Sivokozs, Hamid Reza Ansari, Alokcbre and Riza Budi Prasetya
@RishabhTayal That's nifty, but I would caution against using this all the time instead of reloadData -- you should only need the workaround on first load of the table view.
Doing these extra reloads and layout passes for additional calls to reload the table view will just be wasted CPU processing. So I would recommend only doing it when necessary (the first time) and just using reloadData from then on.
Alright, so I can get my UITableViewCells that are ON screen to initially load in the correct height. But I can't get my UITableViewCells that are off screen to load in the proper height. I have to scroll to them, then scroll up-and-down, to force them to become the proper height.
I'm doing this after my initial call to self.reloadData():
and this in my cellForRowAtIndexPath: cell.placeName.preferredMaxLayoutWidth = CGRectGetWidth(tableView.bounds)
I'm also using the estimatedRowHeight, and overriding override public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath), to return the calculated cell height based upon the height of my UILabel in the cell.
Anyone have any information on getting the off-screen cells to initially load in the correct cell height?
So in order to get the dynamic cell heights to work properly I had to completely configure my cell inside of tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath), to the point where it pretty much looked like my cell configuration in cellForRowAtIndexPath, this is pretty annoying but it works. I'm not sure why I have to configure the entire cell just to get the correct height instead of just returning a number.
For a good example of how to set up your cell in tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) check out this link, http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout , specifically the part on tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath).
Confirmed @gtsifrikas that hack works. Quicker I can move to React the better.... Crazy we have to do all this leg work for ios when it comes to dynamic data and images.
Activity
smileyborg commentedon Oct 10, 2014
Hi @Edig,
I don't think I have enough information to try and help. Did you compare your code to the code of this sample project on GitHub?
You'll probably need to share your entire project (or a sample project that illustrates the issues your seeing) if you would like more help in debugging.
90% of the issues people have with this is that their constraints are not correct, even though they think they are. I recommend double and triple checking that you have all the constraints you need -- it sounds like you could have an ambiguous layout issue.
Edig commentedon Oct 10, 2014
Hi @smileyborg , any email? also I copy the cell you have, exactly the same. And the cells resize perfectly but I need to reload the cell (put it off screen and put it again on screen)
The only thing I dones't have its
self.tableView.registerNib ()
because I have prototype cells
Edig commentedon Oct 10, 2014
Hi @smileyborg I really don't know why but If I add this
Works perfectly, it seems that in the first render of the cells, the system can't determine the exact height of the constraints.
smileyborg commentedon Oct 10, 2014
You can email tfox [at] smileyborg (dot) com. The issue could be related to the preferredMaxLayoutWidth of multi-line labels - not being set the first layout pass.
Edig commentedon Oct 10, 2014
Hi @smileyborg
cell.label2.preferredMaxLayoutWidth = CGRectGetWidth(cell.label2.frame)
work with the new cells, only I have a problem with the first 10 cells that appears without scrolling
smileyborg commentedon Oct 10, 2014
You'll have to share your project to help debug further. Which version of iOS are you testing on?
smileyborg commentedon Oct 10, 2014
This may be the same issue as #7. Can you try adding this code to your UITableViewCell subclass:
If that doesn't work, try the following in your cellForRowAtIndexPath method:
Basically, it seems like there is a bug with the Interface Builder "Automatic" preferredMaxLayoutWidth here.
Edig commentedon Oct 10, 2014
@smileyborg. With that modification it renders the height fine, but the distance between the label1 and label 2 (like your example) differ. When I hide and show the cell it appear with the exact position. Also the height of the cell changes
I try with
cell.placeName.preferredMaxLayoutWidth = CGRectGetWidth(tableView.bounds)
The one its >=0 ( I change to = 0, and the same)
smileyborg commentedon Oct 10, 2014
Interesting, I'm not sure exactly what's going on. But it seems to suggest there are bugs with Apple's implementation of self sizing cells particularly when loading from a Storyboard/nib. You may wish to switch to implementing it in code (as in this example project), as it seems to be more reliable.
Edig commentedon Oct 10, 2014
@smileyborg Ok thanks! I will try it! and I let you know how it goes
PetahChristian commentedon Nov 16, 2014
The problem with cells being loaded from a storyboard is that the cell's width does not initially correspond to the tableView's width (which affects the label's
preferredMaxLayoutWidth). Reloading simply reuses a cell which at that point has the proper frame size.Cells instantiated in code are created with the right dimensions from the start, so they appear correct at the first load.
Edig commentedon Nov 16, 2014
Hi peter,
I had the same problem and I solve it by putting any-any in the class size instead of compact-any
And now works great
Enviado desde mi iPhone
smileyborg commentedon Nov 16, 2014
@PetahChristian You're probably right. But if so, this is definitely a bug on Apple's side. If you can confirm your hypothesis and still see issues with the latest iOS version I would definitely file a radar.
smileyborg commentedon Jan 13, 2015
By the way, not sure if anyone here had made progress on this issue. But I ran into something (potentially) similar recently, and found a workaround that may be helpful...see my comment at the bottom of this article:
smileyborg commentedon Apr 5, 2015
Here's another workaround that may solve this issue: #22 (comment)
8of commentedon May 7, 2015
@smileyborg The comment before last one helped me a lot - thanks! 🆒
RishabhTayal commentedon May 15, 2015
Wrote a nice little extension to fix this issues based in @smileyborg 's answer.
Just call
self.tableView.reloadDataWithAutoSizingCellWorkAround()instead ofself.tableView.reloadData()smileyborg commentedon May 16, 2015
@RishabhTayal That's nifty, but I would caution against using this all the time instead of
reloadData-- you should only need the workaround on first load of the table view.Doing these extra reloads and layout passes for additional calls to reload the table view will just be wasted CPU processing. So I would recommend only doing it when necessary (the first time) and just using
reloadDatafrom then on.RishabhTayal commentedon May 16, 2015
@smileyborg Yeah of-course. That extension is meant only for the first load.
nordringrayhide commentedon Jun 6, 2015
@RishabhTayal +1: you've just saved my mind, yeah it works for me, thanks :-)
JimVanG commentedon Jun 29, 2015
Alright, so I can get my
UITableViewCellsthat are ON screen to initially load in the correct height. But I can't get myUITableViewCellsthat are off screen to load in the proper height. I have to scroll to them, then scroll up-and-down, to force them to become the proper height.I'm doing this after my initial call to
self.reloadData():I have this in my cell subclass:
and this in my
cellForRowAtIndexPath:cell.placeName.preferredMaxLayoutWidth = CGRectGetWidth(tableView.bounds)I'm also using the estimatedRowHeight, and overriding
override public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath), to return the calculated cell height based upon the height of myUILabelin the cell.Anyone have any information on getting the off-screen cells to initially load in the correct cell height?
thank you!
JimVanG commentedon Jun 30, 2015
So in order to get the dynamic cell heights to work properly I had to completely configure my cell inside of
tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath), to the point where it pretty much looked like my cell configuration incellForRowAtIndexPath, this is pretty annoying but it works. I'm not sure why I have to configure the entire cell just to get the correct height instead of just returning a number.For a good example of how to set up your cell in
tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath)check out this link, http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout , specifically the part ontableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath).gtsifrikas commentedon Nov 24, 2016
If you do this:
The first visible cells will get the correct height
grangej commentedon Dec 5, 2016
@gtsifrikas you sir, are a genius :-)
thiagorossener commentedon Mar 20, 2017
@gtsifrikas I could not make this work :(
Here is my code:
My problem is exactly the same problem of that guy:
https://forums.developer.apple.com/thread/67560
Which I believe is the same problem everyone here is facing. So, I turned off the animation and turned on again, as you said, but that didn't work.
This issue looks like a common issue, but until now I couldn't find any good answer for that.
goneale commentedon Nov 26, 2018
Confirmed @gtsifrikas that hack works. Quicker I can move to React the better.... Crazy we have to do all this leg work for ios when it comes to dynamic data and images.
handlermyanmar commentedon Jun 12, 2019
2019 and Xcode still facing this problem. Thanks for the solution guys.
awilliams88 commentedon Aug 9, 2019
@smileyborg U Rock Bro 🤘 - The auto layout bug for multi-line label took so much of my time in debugging 😔 - Thanks for your solution 🙂