UITableView Separator appears in middle of Cell's View

…衆ロ難τιáo~ 提交于 2019-12-11 03:43:21

问题


I am using default iOS 7's TableView Separator. I have custom cells of varying height. When scrolled up and down frequently some of the smaller cells leave behind their separators(perhaps, not sure if this is the cause). So the bigger cell gets cut right in the middle most of the times by the separator.

I have tried resetting cell's edge insets to their previous location but it does not seem to work

-(void)prepareForReuse
{
    [self setSeparatorInset:UIEdgeInsetsZero];
}

回答1:


To avoid this use following steps -

Set cell separator edge inset as -

cell.separatorInset = UIEdgeInsetsMake(0.f, cell.bounds.size.width, 0.f, 0.f);

Set tableview footer view by zero view as-

self.tableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableview.width, 1)];



回答2:


Well, if you subclass UITableViewCell and override layoutSubviews, then make sure you call super.layoutSubviews() at the top of your function body.

Swift

override func layoutSubviews() {
    super.layoutSubviews()

    // do any customization here...
}


来源:https://stackoverflow.com/questions/25585378/uitableview-separator-appears-in-middle-of-cells-view

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