如何在 UITableView 中设置分隔符的全宽 [英] How to set the full width of separator in UITableView

查看:35
本文介绍了如何在 UITableView 中设置分隔符的全宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView 分隔符没有全宽.它在左侧前 10 个像素处结束.我在 viewDidLoad() 中玩弄这段代码.

I have a UITableView where the separators don't have the full width. It ends like 10 pixels before the left side. I was playing around with this code in the viewDidLoad().

self.tableView.layoutMargins = UIEdgeInsetsZero;

当您可以选择自定义或默认选择器时,也在情节提要中.现在填充的所有单元格都没有全宽选择器,但空的单元格具有全宽.

Also in the storyboard when you can select custom or default selectors. Now all the cells that are populated don't have the full-width selectors but the cells that are empty have full width.

我该如何解决这个问题?

How can I fix this?

推荐答案

我从这篇文章中得到了答案:iOS 8 UITableView 分隔符插入 0 不工作

I got the answer from this post: iOS 8 UITableView separator inset 0 not working

只需将此代码添加到您的 UITableViewController

Just add this code on your UITableViewController

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

这篇关于如何在 UITableView 中设置分隔符的全宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆