I tried to make self-sizing cells. I got it to work but with some bug. Which I think is because of wrong constraits. So I kindly ask you if you could look them.
Problem is that after scrolling in tableview, all my views are going to stretch. I thought that it would happen because of not setting height constraint but it seems not to be problem.
Illustration(pretty normal):
After scrolling and coming back up:
And these are my constraints for this view which all of them looks good to me:
And if you want to know how I made cells to resize, then like this:
tableView.estimatedRowHeight = 105//Because my row height is 105
tableView.rowHeight = UITableViewAutomaticDimension
When this sort of thing happens, the implication is that you are not supplying sufficient constraints to size the cell's contentView from the inside out. You can readily confirm this using View Debugging to pause the app when you see your incorrectly sized cell; you will then be able to study the actual values of your constraints and see what the problem is.
EDIT Now that you've posted your constraints, it's easy to see what the problem is: There is nothing at all connecting your interface elements to the bottom of the contentView. But that is the whole point of self-sizing cells: you must have, as I already said, sufficient constraints running all the way from the top of the contentView to the bottom of the contentView. That is what determines the height — and so you are not determining it.
Related
I know that to enable self-sizing we need to set to estimatedRowHeight a specific value but I can't get the purpose of doing it. For example, what if I set the property to 600 but my actual cell size is only 40 ?
In my projects, I always set a random value to it and it works well.
Please explain to me, I'm very curious. Thank a lot.
It is used to estimate the height of the content view (not the table view's size itself). Table view needs to know the height of its content to allow scrolling smoothly without actually loading all the cells. If your estimatedRowHeight is quite different from the real cell's height, then when you try to scroll you may see the scroll indicator flickers. Or when you try to reload table view, the high possibility that you may see the cells appears in a weird way and with unexpected animations.
It helps auto layout prepare an initial value for the display until the actual height is being calculated by the constraints you set to the elements inside the cell from top to bottom
I'm looking for the best approach to dynamically increase the height of both the UITextView and the TableView Cell height while the user is entering data. Ive searched and found a lot of different answers some more complex than others.
My table has Static Cells
TextView1
Ive added the following to my viewDidLoad
renewalsStratTableView.estimatedRowHeight = 150
renewalsStratTableView.rowHeight = UITableViewAutomaticDimension
But that doesn't seem to do much of anything. I am also not sure on how to dynamically increase the UITextView as the user adds text.
I wrote a tutorial that addresses the exact issue you're having. Most of the answers are too complex and perform unnecessary size calculations on text views.
You're already on a good path by setting the estimated row height and row height to automatic dimension, but there are a few other steps to make your table view fully dynamic.
For example, you have to disable scrolling in the text view and you have to call renewalsStratTableView.beginUpdates() and renewalsStratTableView.endUpdates() every time your user changes text.
For a detailed explanation and a fully working sample code, check out my post.
in my uitableview, i subclassed uitableviewcell's, and i added a subview to the contentview with flexible width and height. the cells are of dynamic height.
when the tableview first loads, everything is fine. however, as i start to scroll around, separators start disappearing, and they happen at the same places every launch. scrolling around some more will recover the lost separators.
anyone else encounter this?
I don't know how specific this will be to your project, but I'll tell you what I figured out. Overriding my layoutSubviews method was the problem. I looked at the view hierarchy of my cell before and after I called [super layoutSubviews] and discovered that this method was making the contentView 1 pixel shorter and added a new view below it 1 pixel high with a background color of 0.88/0.88/0.88.
If you can't live with some of the side effects of the superclass implementation, it looks like this view must be added manually.
The problem was related to the dynamic heights. Using either ceilf or floorf solved the problem.
so I wanted to have a table with multiple sections and each one with multiple cells. By touching a section's header, this section should expand and the others should minimize, leaving only the header visible.
I looked up some suggestions and accomplished this by a) setting the cell's height to 0 and reloding the data animated and b) adding a button as a subview to the cell's header.
Anyway, while it works fine, mainly, there is minor problem, namely, I can see a 'flickering' below each cell's header, when the change is animated. I guess its because the cell's content is redrawn. And I don't like it!
I wanted to ask whether the approach is correct or generally your opinion about it. Moreover I would be really happy, if someone could hint me why the 'flickering' appears in my table :)
EDIT: Another thing is, that if I press on a section, it appears like all the section headers are pressed.... maybe someone has seen this weird artifact also?
You should remove cells instead of setting height to 0.
You will have less call to data source and delegate and no more artifacts.
I'm having a weird issue with a particular UITableView in my iPhone devel experience here. If you look at the following screenshot:
alt text http://dl-client.getdropbox.com/u/57676/brokencell.png
you'll notice a strike through going through the middle of the 'Jane Aba' cell.
Any idea what might be causing this odd graphic display? It's true for both the simulator and for the actual device running 2.2 SDK.
As requested, here's my -tableView:cellForRowIndexPath: method:
* EDIT *
I've located the problem. I'm not entirely sure why this is the problem, but it is. In my RootViewController, I have the following line of code in my -initWithCoder: method:
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
When I comment that out, the cell (which is not in the RootViewController, but a secondary controller) it's resolved. Any idea why this might be the case?
I've had a similar problem. For me, the single line was caused by a superfluous view that was created but never sized or placed correctly and so was 1 pixel high, floating over everything else. You can also cause this by confusing a UINavigationController about its set of subviews (by adding views directly to its layout container).
Look through your UI (xib files and programmatically created views) for a view that shouldn't be there or is otherwise not being used. It might be helpful to write some code to dump a UI Hierarchy, so you can see what views are where.
Are you doing anything special in your -tableView:heightForRowAtIndexPath: method?
It looks to me like the height of the row is being set incorrectly, so the contents of the cell are expanding outside of its bounds.
The problem disappears when you set the cell height for the table view to 1 pixel in IB. It seems that before you populate the table, an empty table is drawn with the outlines of the cell height set in IB.
Don't set the cell height to 0. IB doesn't like that. :-)