objective-c 有没有办法从 UITableView 中删除分隔线?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/925115/
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
Is there a way to remove the separator line from a UITableView?
提问by Tricky
I'm looking for a way to completely remove the separator line in a UITableView when in the plain mode. This is done automatically in grouped, but this also changes the dimensions of the table in a way that is hard to measure. I have set the seperator line color to colorClear. But this does not completely solve the problem.
我正在寻找一种在纯模式下完全删除 UITableView 中分隔线的方法。这是在分组中自动完成的,但这也会以难以衡量的方式改变表格的维度。我已将分隔线颜色设置为 colorClear。但这并不能完全解决问题。
As I am trying to draw a custom background view in the cells, and I want the cells to be seamless, the one pixel line that remains in-between is causing me problems. Is there a more elegant workaround then using a grouped view and then stretching it?
由于我试图在单元格中绘制自定义背景视图,并且我希望单元格是无缝的,因此保留在中间的一条像素线给我带来了问题。有没有比使用分组视图然后拉伸它更优雅的解决方法?
回答by Bart Jacobs
You can do this with the UITableViewproperty separatorStyle. Make sure the property is set to UITableViewCellSeparatorStyleNoneand you're set.
您可以使用该UITableView属性执行此操作separatorStyle。确保该属性设置为UITableViewCellSeparatorStyleNone并且您已设置。
Objective-C
目标-C
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
In Swift (prior to 3)
在 Swift 中(3 之前)
tableView.separatorStyle = .None
In Swift 3/4/5
在斯威夫特 3/4/5
tableView.separatorStyle = .none
回答by Kevin DiTraglia
You can do this in the storyboard / xib editor as well. Just set Seperator to none.
您也可以在故事板/xib 编辑器中执行此操作。只需将分隔符设置为无。


回答by imthi
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
回答by Sig Myers
I still had a dark grey line after attempting the other answers. I had to add the following two lines to make everything "invisible" in terms of row lines between cells.
尝试其他答案后,我仍然有一条深灰色线。我必须添加以下两行,以使单元格之间的行线方面的所有内容“不可见”。
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.separatorColor = [UIColor clearColor];
回答by Mohsin Qureshi
In interface Builder set table view separator "None"
在界面生成器中设置表视图分隔符“无”
and those separator lines which are shown after the last cell can be remove by following approach.
Best approach is to assign Empty View to tableView FooterView in viewDidLoad
并且可以通过以下方法删除最后一个单元格之后显示的分隔线。最好的方法是在 viewDidLoad 中将 Empty View 分配给 tableView FooterView
self.tableView.tableFooterView = UIView()
self.tableView.tableFooterView = UIView()
回答by Mohsen
In Swift:
在斯威夫特:
tableView.separatorStyle = .None
回答by Siddhesh Mahadeshwar
There is bug a iOS 9 beta 4: the separator line appears between UITableViewCells even if you set separatorStyleto UITableViewCellSeparatorStyleNonefrom the storyboard. To get around this, you have to set it from code, because as of now there is a bug from storyboard. Hope they will fix it in future beta.
iOS 9 beta 4 存在错误:UITableViewCell即使您从情节提要中设置separatorStyle为UITableViewCellSeparatorStyleNone,分隔线也会出现在s之间。为了解决这个问题,你必须从代码中设置它,因为到目前为止故事板有一个错误。希望他们会在未来的测试版中修复它。
Here's the code to set it:
这是设置它的代码:
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
回答by Ashu
In the ViewDidLoad Method, you have to write this line.
在 ViewDidLoad 方法中,你必须写这一行。
tableViews.separatorStyle = UITableViewCellSeparatorStyleNone;
This is working Code.
这是工作代码。
回答by Aatish Javiya
In your viewDidLoad:
在您的viewDidLoad:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
{
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}

