简体   繁体   中英

UITableView separator at wrong position

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] .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM