-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No auto layout on first load tablewview #10
Comments
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. |
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 |
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. |
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. |
Hi @smileyborg work with the new cells, only I have a problem with the first 10 cells that appears without scrolling |
You'll have to share your project to help debug further. Which version of iOS are you testing on? |
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. |
@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) |
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. |
@smileyborg Ok thanks! I will try it! and I let you know how it goes |
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 Cells instantiated in code are created with the right dimensions from the start, so they appear correct at the first load. |
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
|
@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:
|
Here's another workaround that may solve this issue: #22 (comment) |
@smileyborg The comment before last one helped me a lot - thanks! 🆒 |
Wrote a nice little extension to fix this issues based in @smileyborg 's answer.
Just call |
@RishabhTayal That's nifty, but I would caution against using this all the time instead of 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 |
@smileyborg Yeah of-course. That extension is meant only for the first load. |
@RishabhTayal +1: you've just saved my mind, yeah it works for me, thanks :-) |
Alright, so I can get my I'm doing this after my initial call to
I have this in my cell subclass:
and this in my I'm also using the estimatedRowHeight, and overriding Anyone have any information on getting the off-screen cells to initially load in the correct cell height? thank you! |
So in order to get the dynamic cell heights to work properly I had to completely configure my cell inside of For a good example of how to set up your cell in |
If you do this: tableView.reloadData()
UIView.setAnimationsEnabled(false)
tableView.beginUpdates()
tableView.endUpdates()
UIView.setAnimationsEnabled(true) The first visible cells will get the correct height |
@gtsifrikas you sir, are a genius :-) |
@gtsifrikas I could not make this work :( Here is my code:
My problem is exactly the same problem of that guy: 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. |
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. |
2019 and Xcode still facing this problem. Thanks for the solution guys. |
@smileyborg U Rock Bro 🤘 - The auto layout bug for multi-line label took so much of my time in debugging 😔 - Thanks for your solution 🙂 |
I have a problem. I create a TableViewController with dynamic height on the cells. I follow this answer
http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights/18746930#18746930
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 have my code, mostly the same as that post
Any ideas? the constraints are exactly the same as the post, I just modify the font (I try with the font he propose and its the same error)
Edit: I try it on iPhone 6 (Physically). and iPhone 4S (Simulator)
Best,
The text was updated successfully, but these errors were encountered: