ios 移除 UITableView 分隔线

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40332305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 10:40:53  来源:igfitidea点击:

Remove UITableView separator line

iosobjective-cuitableview

提问by Evgeniy Kleban

I want to remove the line between 2 views. The line that separates 2 UITableViewCells:

我想删除 2 个视图之间的线。分隔 2UITableViewCell秒的线:

enter image description here

在此处输入图片说明

I declared table view as following:

我声明表视图如下:

self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
self.tableView.scrollEnabled = NO;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.estimatedRowHeight = 85.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

So i actually wrote - self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

所以我实际上写了 - self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

Why does it still exist?

为什么它仍然存在?

回答by Jamshed Alam

Objective-C :

目标-C:

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Swift:

迅速:

self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None

Swift 5.0 renamed it in :

Swift 5.0 将其重命名为:

self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none

Apply the line in viewDidLoad() method.

在 viewDidLoad() 方法中应用该行。

If you want to do it from nib file, set the tableView's Separator property to None

如果您想从 nib 文件中执行此操作,请将 tableView 的 Separator 属性设置为 None

回答by Nirav Panchal

For Swift 4:

对于Swift 4:

tableView.separatorStyle = .none

回答by Sumayya Ansari

Hide tableView separators using UI

使用 UI 隐藏 tableView 分隔符

Here you select TableView 'Separator' property as 'None'.

在这里,您将 TableView 的“分隔符”属性选择为“无”。

https://i.stack.imgur.com/8KyH5.png

https://i.stack.imgur.com/8KyH5.png

回答by kishan savani

For Swift 5:

对于Swift 5

 viewDidLoad(){
     tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
    }

For Objective-C:

对于Objective-C

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];


or you can use interface builder instead

或者您可以改用界面构建器

enter image description here

在此处输入图片说明



For more information

想要查询更多的信息

SeparatorStyle

分隔符样式

回答by Leo

In Swift 4.2 you can conveniently use dot notation on a tableView's separatorStyle. Like so:

在雨燕4.2,你可以方便地使用点符号上tableViewseparatorStyle。像这样:

tableView.separatorStyle = .none

tableView.separatorStyle = .none

回答by Mohamed Adly

You can use the following code because it will not remove the line separators of the sections.:

您可以使用以下代码,因为它不会删除部分的行分隔符。:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    // Your code here //

    cell.separatorInset = UIEdgeInsetsMake(0.f, [UIScreen mainScreen].bounds.size.width, 0.f, 0.f);

}

回答by clopex

My problem was when I add tableView trough code and I have separate func to show tableview and add it on mainView (slide from bottom) I needed to add this tableView.separatorStyle = .none in that func where tableView is added on mainView and constraint it.

我的问题是当我添加 tableView 槽代码并且我有单独的 func 来显示 tableview 并将它添加到 mainView(从底部滑动)我需要添加这个 tableView.separatorStyle = .none 在那个 func 中 tableView 添加到 mainView 并约束它.

回答by Umer Khan

add this line

添加这一行

tableView.separatorStyle = .none