On selection I change the height of an UITableViewCell (loaded from a nib).
But the separator line is at a wrong position when I do this.
In the screenshot the first row is selected, and therefore bigger than the other ones.
From the separator positions it looks like the cell after the selected cell would be the big one. The second cell "has" exactly the size the first cell should have.
To change the height I save the selected indexpath in tableView:didSelectRowAtIndexPath: and compare it in tableView:heightForRowAtIndexPath:. If the indexpaths are the same I return the increased height. With the help of some NSLog I made sure that the correct height is returned.
And if I would resize the wrong cells the views of the cell would overlap, this doesn't happen.
If I click Line 3 of the first cell the tableView:didSelectRowAtIndexPath: fires and the indexpath is the one for the first cell. So I guess the heights are correct, and the tableview draws the separators on the wrong position.
Does anybody has an idea what I did wrong?
Any solutions? Or should I file another bug with apple?
Edit: If I don't reuse my cells it works as expected.
It turned out that I had switched off "Autoresize subviews" for the UITableViewCell.
If I turn that option on it works as expected.
I had a similar problem. In my case I was using layoutSubviews to do custom layout on my cell. The separator was in the wrong position and the layout of the accessory view was also out.
In my case the issue was failing to call [super layoutSubviews].
Related
I am making a to do list app and have 3 custom cell types. For task cells, it is just an imageview on the left and a textview on the right. I would like the cell to automatically resize itself when the textview text is to large for a single line.
I have added the correct constraints and have added this to viewWillAppear
tableView.estimatedRowHeight = 30
tableView.rowHeight = UITableView.automaticDimension
However, when going into the view with the tableview, the cells remain small for a second and then expand to their correct size. Also, when initially adding the task, the cell doesn't resize unless either going back and opening the view controller again or the tableview is scrolled up until the cell is out of view and then letting go.
This is very odd behaviour and even happens when removing the two lines above from viewWillAppear. It just happens for no reason.
I would like the cells to be of the right size when going into the view and not resizing a second later.
An example of what this looks like is below
Okay so I finally found the answer. I made my cell programmatically with auto layout and some of that was setup in the layoutSubviews() method inside the cell. This method is only called when needed. So when scrolling up or down.
To fix this, in your cellForRowAt method, just call
cell.layoutSubviews()
I have a TableViewCell that has 2 StackViews. One of the StackViews has 3 components and one of which is hidden. By pressing on a button, I want the hidden UIImageView to appear. While my code does this, it does not format it correctly as the height of the TableViewCell does not change, as I would like it to. I have tried calls to sizeToFit(), but I am starting to realize that this will not affect the height of a cell. When the cell leaves the view and comes back, it draws correctly. How can I update the height of the cell when the button is pressed?
After writing out this question, I started to realize that the problem was from the cell's height. After doing a little bit more research I found out that this can be achieved with the
tableView.beginUpdates()
tableView.endUpdates()
I had to create a delegate and add a delegate method to reference back to the ViewController.
Hope this helps someone else!
I am using an OHAttributedLabel within my UITableViewCells to display some text partly in regular font and partly in italics. My tableview rows are structured such that 8 rows are displayed on the screen.
When I scroll down the 9th cell appears to be empty. Only when I scroll down far enough suc h that the ninth cell is out of the view and then scroll back up is when the text in the 9th cell is displayed.
I noticed that when I use the textLabel property of UITableViewCell I do not have this problem. Can someone throw insight into why I am seeing such behavior using OHAttributedLabel and how to fix it?
I have a tableview with UiTableViewCells from a XIB and I want to animate a change of cell height when selected and showing/hiding some elements.
Now, for the animated change of height there's no problems, I've done it with the tutorial in this answer .
The problem is how to toggle some elements!
I can't figure out how to solve this problem! Putting on the xib the elements, they cover the cell above; by code I can't find a method to call when a cell is opened and the animation i finished!
Any ideas?
Thanks to all!
There may be an easier way than this, but one way would be instead of changing the cell height and adding the new components in the animation block, set a flag for that row that it should be expanded then in your animation block call
[tableview reloadData]
And in your
heightForRowAtIndexPath
method return the new cell height and in the
cellForRowAtIndexPath
method of your delegate return the new version of the cell with the additional elements.
I have a UITableView and I am having an issue with whenever I try to click on the Cell. When the cell is highlighted it puts some test on top of the text that is already on the cell make the text on the cell hard to read. This only happens while I have the cell highlighted.
Please help me with this issue.
Thanks
I had a similar problem and then realised that I wasn't using the cell dequeuing thing properly and what had happened is that every time the cell is reused a new UIlabel was added and the text from the datasource set to that, but the UILabels from the previous time the cell was showing were still there. But you only see them when the cell is highlighted because when it's not highlighted the background is not clear, but when the cell is highlighted then the UIlabels become clear and you see the other UIlabels that are behind it.
It's quite serious as everytime cell's are dequeued (ie everytime you scroll on the tableview) all of the subviews you've added a duplicated. And it increases memory usage severely.
To fix I used the code from the apple docs on customizing table cells. You have to use tags to retrieve the subviews if the cell is dequeued.:
http://developer.apple.com/iphone/library/documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW15