6

I've build an app which contains an UITableView with a bunch of cells. Inside the cells I've got a view, which fill the whole cell. I've configured the tableview like this:

tableView.separatorStyle = .none
tableView.backgroundColor = UIColor(red: 24/255.0, green: 34/255.0, blue: 41/255.0, alpha: 100)
tableView.separatorColor = UIColor(red: 26/255.0, green: 34/255.0, blue: 40/255.0, alpha: 100)

Whenever the app enters the foreground, I got those little lines flickering for 0.5 seconds or so. To be clear, I don't want those.

enter image description here

And this is how it looks like when the app fully entered the foreground, and how it is supposed to look like:

enter image description here

Any ideas how to get rid of them?

EDIT 1:

I'm starting to doubt that the flickering is related to the separators, because it is only happening between cells in a section, not between the section-cell and the first cell in a section. I've grabbed some screenshots of the view hierarchy and the constraints related to the view (Foreground view) I show in the cell.

enter image description here enter image description here

EDIT 2:

If I set the top and bottom constraint to -2 instead of 0, there's no flickering at all, however it's not as I want it visually. So the flickering is not related to the separators at all.

16
  • Where are you setting the tableView.separatorStyle = .none? Is it in viewDidLoad? Aug 19, 2018 at 17:17
  • Yea, it's in the viewDidLoad. I tried viewWillAppear too, without any luck.
    – Recusiwe
    Aug 19, 2018 at 19:18
  • Did u trying this in Simulator or Real Device ???
    – McDonal_11
    Aug 20, 2018 at 12:32
  • 10
    If you build a minimal working example, which can be used to replicate the issue, it would be much easier to help. Aug 22, 2018 at 5:01
  • 4
    You aren't supposed to vote down if an answer doesn't work for you. Just imagine if people simply didn't like your question just for kicks and started voting down, how'd the situation be for you. Voting down should be done when the answer either is way off base, or is not presented clearly. Reps are prized possession, you should not eat into other people's for no good reason.
    – Manganese
    Aug 24, 2018 at 5:21

13 Answers 13

2

Trick for removing the cell separators.

Objective-C

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.tableFooterView = [UIView new];
}

Swift

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.tableFooterView = UIView()
}
1

Usually flickering happens when you're returning a wrong heightForRowAtIndexPath.
In your case, you're returning a little smaller than your cell's actual height I guess.
So try to set "clipToBounds" of your cell to "true" and check if it works.

2
  • 1
    @Recusiwe one more strange thing that I noticed is that the ContentView of your TableViewCell is missing. By default, when you're dragging UITableViewCell to IB it comes with a ContentView. But in your screenshot, it's missing. Or you've just renamed it?
    – arturdev
    Aug 23, 2018 at 6:48
  • I just renamed it, it's the "Background Container View"
    – Recusiwe
    Aug 23, 2018 at 9:17
1

Try setting "Renders with edge antialiasing" to YES in your info.plist.

1

I think here your issue with UITableViewStyle. Right now you are using UITableViewStyle Grouped. So, line between cell isn't UITableViewCellSeparator it's Group Table 1 pixel header and footer space. So,

I have two solutions:

  • Either use UITableView background color same as cell background color.
  • Change UITableView style to Plain

GroupTable SS

enter image description here

or

PlainTable SS

enter image description here

I hope it'll help you. And solve your issue :)

2
  • Where do you see I use grouped? I use Plain actually.
    – Recusiwe
    Aug 25, 2018 at 22:31
  • Share your class file.. It'll better to crack Aug 26, 2018 at 10:55
1

I think it's not related to the separator, because the separator doesn't cover the whole screen, it must be related to your constraints, try changing the background color of the BackgroundContainerView, the DepartureCell and the TableView, one of these 3 views should have the dark grey color as a background color.

1

Would it be possible that the tableview is inherited from another one and seperatorStyle could be set different in the super class? Then, you need override it.

0

Set this in viewDidLoad()

tableView.separatorStyle = .none
1
0

You can do it as per follows, from your storyboard to avoid that separator from UITableView.

Do it like this

0
0

If you set

tableView.separatorStyle = .none

on viewDidLoad(), it will flicker

you need to it before like in viewWillAppear() or in the storyboard

1
  • 1
    Heh, did you just vote me down? Share proper code and we could help you better. Aug 23, 2018 at 9:16
0

Try setting the tableview separator color with full transparency it might help

tableView.separatorColor = UIColor(red: 26/255.0, green: 34/255.0, blue: 40/255.0, alpha: 0)

Do this in viewWillAppear

If that will not help check the view hierarchy maybe there is an issue with the cell rendering in

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)

Check this post and its swift 4 update

or try adding this extension to your ViewController

extension UITableViewCell {
func removeCellSeparators() {
    for subview in subviews {
        if subview != contentView && subview.frame.width == frame.width {
            subview.removeFromSuperview()
        }
    }
  }
}

then try calling it in just before you return the cell

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "YourCellIdentifier", for: indexPath)

    cell.removeSeparators()

return cell
}

if this doesn't help then please post more information about your setup, code or maybe host a minimal version of your app with the tableView having the issue on gitHub so that I can help.

EDIT 1:

Try setting the rowHeight / cellHeight to 15 pixels more than what it currently is if that will solve your problem than the cellHeight is what needs tweaking could be that it only needs to be 2-4 pixels higher. Probably as the app is entering the foreground autolayout is trying to do what it can do show everything as you want however some constraints are ambiguous therefore whilst entering from the background there is the view appearing animation from the system for about half a second and there is your flickering as well.

9
  • Both solutions are not working. Plus the linked answer is only for section separators. Aug 22, 2018 at 13:08
  • Are you using storyboards or creating the tableView in code? Aug 22, 2018 at 13:19
  • I use storyboards, and I'm starting to think that the problems isn't related to separators, but my contraints.
    – Recusiwe
    Aug 22, 2018 at 19:34
  • Because the flickering only occurs in between cells in sections, not between the sections and the first cell.
    – Recusiwe
    Aug 22, 2018 at 20:00
  • Could you extract the tableView code into a separate project so I can replicate the issue and be able to help you or share the current project on github?? Aug 23, 2018 at 4:01
0

Can you use Xcode "Debug View Hierarchy" to find question View , and use "KVC" remove that view. ps. my english is poor , i hope i can help you

0
0
  1. From storyboard select table view separator to None.
  2. In Separator Inset select custom and remove left value make it from 15 to 0.
  3. Build and run it again now check.

enter image description here

0

Make tableView's backgroundColor and separatorColor exactly the same as in:

tableView.backgroundColor = UIColor(red: 24/255.0, green: 34/255.0, blue: 41/255.0, alpha: 100)
tableView.separatorColor = UIColor(red: 24/255.0, green: 34/255.0, blue: 41/255.0, alpha: 100)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.