简体   繁体   English

UITableView分隔符在错误的位置

[英]UITableView separator at wrong position

On selection I change the height of an UITableViewCell (loaded from a nib). 选择时,我更改了UITableViewCell的高度(从笔尖加载)。
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: . 要更改高度,我将选定的索引路径保存在tableView:didSelectRowAtIndexPath: ,并在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. 在某些NSLog的帮助下,我确保返回了正确的高度。
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. 如果单击第一个单元格的第Line 3 ,则会触发tableView:didSelectRowAtIndexPath: :,并且indexpath是第一个单元格的索引路径。 So I guess the heights are correct, and the tableview draws the separators on the wrong position. 因此,我认为高度是正确的,并且tableview在错误的位置绘制了分隔符。


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. 原来,我已经为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. 就我而言,我正在使用layoutSubviews在单元格上进行自定义布局。 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] . 就我而言,问题是无法调用[super layoutSubviews]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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