iOS 7.1 UitableviewCell content overlaps with ones below

旧时模样 提交于 2019-11-28 05:19:32
RyanJM

The issue has to do with the height of your cell. It isn't going to dynamically adjust that for you.

You'll probably notice that as you scroll and the view above goes out of view the overlapping text will disappear with it.

If you are wanting your text to clip at a certain height, then you need to set the number of lines, rather than setting it to 0 since that will let it continue forever.

The lineBreakMode won't take effect since it isn't stopped.

Optionally you could try to set clipping on the contentView to make sure all subviews stay inside.

Depending on the end result you want, you could do dynamic heights and change based on the content. There are a bunch of SO questions related to doing this.

Update - clipping the contentView

I'd have to try it out myself, but in lieu of that, here are a couple links related to clipping the contentView:

Looks like this works:

cell.clipsToBounds = YES;

Here is the Perfect solution of Overlapping content in Cells.

Just use below code in cellForRowAtIndexPath after allocating cell and before adding subviews.

for (id object in cell.contentView.subviews)
{
    [object removeFromSuperview];
}  

Actually the overlapping is occurring because whenever you scroll the tableview its allocating your added view again and again. So above code will solve your problem by removing the existing views from cell's contentView.

Now You can see the memory debug session after applying above code, your memory is stable this time.

Hope it'll help you.

Thanks !

This is problem with recreating cell contents. Try with following code segment.

for(UIView *view in cell.contentView.subviews){  
        if ([view isKindOfClass:[UIView class]]) {  
            [view removeFromSuperview];   
        }
    }

@Gaurav your answer should be the accepted answer. Thanks!

for object in cell.contentView.subviews
            {
                object.removeFromSuperview();
            }

had similar behavior in iOS 8, using storyboard / IB.

fix was to add a Bottom Space to: Superview constraint from the bottom-most view to bottom of the prototype cell's Content View. The other views and constraints were all anchored from the top.

Are you using storyboards? If so, select the table view controller in storyboards and uncheck the "Under bottom bars" You can also do this programmatically.

If your TVC inherits from a nav view controller or a tab view controller, you may need to uncheck this layout option on the parent view instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!