Tancrede Chazallet
Tancrede Chazallet

Reputation: 7245

UITableView row separator issue

My app is composed of UITableView with dynamic height rows, all with AutoLayout (programmatically).

My UITableView doesn't have any separator, I draw them myself on each row (just one UIView of 1px...). So the UITableView is set without any separator.

This works fine. But some random time, especially when there are a lot of different row height in the view, some separation appears between some row. Which make the background (orange) visible and look like a bug (See the image below).

I kinda think it's a bug intern to iOS while managing height of each rows, it could be a value close to 0 that the system try to display and so show 1px height line.

I'm open to every suggestion which could be a solution.

EDIT

I added a bigger picture which shows well the problem. I can't add the cellForRowAtIndexPath code because it is very complex. What I can say is that :

Important note : The problem doesn't show up on simulator even with exactly the same data.

EDIT 2

Here's how I set white background to my cell

self.backgroundColor = [UIColor clearColor];    
self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageWithColor:[UIColor whiteColor]]];

separator issue

Upvotes: 3

Views: 1026

Answers (2)

Andris Zalitis
Andris Zalitis

Reputation: 2384

Perhaps the problem is caused by your code providing dynamic cell heights with decimal fraction less than one retina pixel (0.5). Try rounding the value that you return in - tableView:heightForRowAtIndexPath: (if you don't round it already) and see if that helps.

Upvotes: 7

Joseph Chen
Joseph Chen

Reputation: 1530

One possible workaround (not knowing more about your UITableViewDataSource methods and UITableViewCell implementation) is to change the view behind your tableview to be white. The gaps will still be there but will be the same color as the cells above and below, and therefore not visible.

The problem shown in your image is only with Row 4, correct? What are the orange areas above and below the tableview rows?

If the upper and lower orange areas are not part of the tableview, you could try:

tableView.backgroundColor = [UIColor whiteColor];

If the orange areas are the header and footer of the tableview, you could set the tableview's backgroundColor to white, and then set the views for the header and footer views to have orange backgrounds.

Upvotes: 0

Related Questions