Remove UITableView separator line
IosObjective CUitableviewIos Problem Overview
I want to remove the line between 2 views. The line that separates 2 UITableViewCell
s:
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;
Why does it still exist?
Ios Solutions
Solution 1 - Ios
Objective-C :
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Swift:
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
Swift 5.0 renamed it in :
self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
Apply the line in viewDidLoad() method.
If you want to do it from nib file, set the tableView's Separator property to None
Solution 2 - Ios
For Swift 4:
tableView.separatorStyle = .none
Solution 3 - Ios
For Swift 5 :
viewDidLoad(){
tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
}
For Objective-C :
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
or you can use interface builder instead
For more information
Solution 4 - Ios
Hide tableView separators using UI
Here you select TableView 'Separator' property as 'None'.
Solution 5 - Ios
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);
}
Solution 6 - Ios
In Swift 4.2 you can conveniently use dot notation on a tableView
's separatorStyle
. Like so:
tableView.separatorStyle = .none
Solution 7 - Ios
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.
Solution 8 - Ios
As @gonsee point out: "Setting separatorStyle seems to have no effect unless the table view is in the window's view hierarchy. If you have a table view on some UIView subclass"
You should set the seperatorStyle in viewDidAppear if you your table in UIView.
override func viewDidAppear(_ animated: Bool) {
self.contentView.documentTableView.separatorStyle = .none
}
Solution 9 - Ios
you can archive these things in different ways
-
you can also use this one line of code in
viewDidLoad()
override func viewDidLoad() { super.viewDidLoad() tableView.tableFooterView = UIView() }
-
set the code in
viewDidLoad()
override func viewDidLoad() { super.viewDidLoad() tableView.separatorStyle = .none }
Solution 10 - Ios
add this line
tableView.separatorStyle = .none
Solution 11 - Ios
In viewDidLoad add tableView.separatorStyle = .none
Example:
override func viewDidLoad() {
super.viewDidLoad()
...
self.tableView.separatorStyle = .none // <---
...
}