Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 448 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iOS 8 UITableView separator inset 0 not working

#11
You can use UIAppearance once, at your application startup (before UI is loaded), to set it as default global settings:

// iOS 7:
[[UITableView appearance] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];

[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];

// iOS 8:
if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {

[[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];
[[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];
[[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];

}


This way, you keep your UIViewController's code clean and can always override it if you want.
Reply

#12
I went through all these wonderful answers and realized most of them do not work with iOS 8, or do work but the separator changes size during animation causing unwanted flashing. This is what I ended up doing in my app delegate before creating the window:

[[UITableView appearance] setSeparatorInset:UIEdgeInsetsZero];
[[UITableViewCell appearance] setSeparatorInset:UIEdgeInsetsZero];

if ([UITableView instancesRespondToSelector:@selector(setLayoutMargins:)]) {
[[UITableView appearance] setLayoutMargins:UIEdgeInsetsZero];
[[UITableViewCell appearance] setLayoutMargins:UIEdgeInsetsZero];
[[UITableViewCell appearance] setPreservesSuperviewLayoutMargins:NO];
}

And this is what I added to my UITableViewController:

-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];

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

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

I didn't need to add anything else. Thanks to everyone who provided the crucial bits.
Reply

#13
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// ... Get the cell
cell.separatorInset = UIEdgeInsetsMake(0.f, 20.f, 0.f, [UIScreen mainScreen].bounds.size.width - 20);
// others
return cell;
}

For any specific cell you want to hide the separator.
Reply

#14
Lukasz answer in Swift:

// iOS 7:
UITableView.appearance().separatorStyle = .SingleLine
UITableView.appearance().separatorInset = UIEdgeInsetsZero
UITableViewCell.appearance().separatorInset = UIEdgeInsetsZero

// iOS 8:
if UITableView.instancesRespondToSelector("setLayoutMargins:") {
UITableView.appearance().layoutMargins = UIEdgeInsetsZero
UITableViewCell.appearance().layoutMargins = UIEdgeInsetsZero
UITableViewCell.appearance().preservesSuperviewLayoutMargins = false
}
Reply

#15
Simple solution in **Swift** for **iOS 8** with a custom `UITableViewCell`

override func awakeFromNib() {
super.awakeFromNib()

self.layoutMargins = UIEdgeInsetsZero
self.separatorInset = UIEdgeInsetsZero
}

In this way you are setting `layoutMargin` and `separatorInset` just one time instead of doing it for each `willDisplayCell` as most of the above answers suggest.

If you are using a custom `UITableViewCell` this is the correct place to do it.
Otherwise you should do it in `tableView:cellForRowAtIndexPath`.

Just another hint: you don't need to set `preservesSuperviewLayoutMargins = false` because default value is already `NO`!
Reply

#16
In a more compact way than the most voted answer...

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

if ([cell respondsToSelector:@selector(setSeparatorInset:)] && [cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)] && [cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
[cell setPreservesSuperviewLayoutMargins:NO];
[cell setLayoutMargins:UIEdgeInsetsZero];
}

}
Reply

#17
In iOS8:

Adding this to my UITableViewCell Subclass:

- (UIEdgeInsets)layoutMargins {
return UIEdgeInsetsZero;
}

and this to "tableView:cellForRowAtIndexPath" or "tableView:willDisplayCell":

[editCell setSeparatorInset:UIEdgeInsetsZero];

WORKED for me.
Reply

#18
I didn't have any real luck with any of the solutions above. I'm using NIB files for my tables cells. I "fixed" this by adding a label with a height of 1. I changed the background of the label to black, pinned the label to the bottom of the nib, and then pinned the bottom of the rest of my contents to the added label. Now I have a black border running along the bottom of my cells.

To me, this feels like more of a hack, but it does work.

My only other choice was to just eliminate the border completely. I'm still deciding whether I'll just go with that.
Reply

#19
iOS 8 and later. Swift 2.0 and later:

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.separatorInset = UIEdgeInsetsZero
if #available(iOS 8.0, *) {
cell.layoutMargins = UIEdgeInsetsZero
} else {
// Fallback on earlier versions
}
}
Reply

#20
After having seen the answers at floor 3, I tried to figure out what the relationship of setting up the separator between TableView & TableViewCell and did some test. Here are my conclusions:

1. we can consider that setting the cell's separator to zero has to move the separator in two steps: first step is to set cell's **separatorinset** to zero. second step is to set cell's **marginlayout** to zero.

2. set the TableView's **separatorinset** and **marginlayout** can affect the Cell's **separatorinset**. However, from the test, I find that the TableView's **separatorinset** seem to be useless, TableView's **marginlayout** can actually affect cell's **marginlayout**.

3. set Cell's PreservesSuperviewLayoutMargins = false, can cut off TableView's **marginlayout** effect on Cells.

4. one of the solutions:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = UITableViewCell()

cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero

return cell
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through