ios tableview last cell in table missing separator swift - ios

My table view's last cell was working fine and showing a separator. However when testing my app now I realized that the separator no longer comes up anymore for the last cell of the table. The only thing I can think of that might have caused this to happen was playing around with some of the preset tableview settings in main.storyboard.I checked but didn't notice anything different. Any one know what I might have changed to cause this, or now what to try to fix it ? Thank you

By default, the last cell of a tableView does not show a separator. Someway to work around it include using a 1px UIView with background Color as separator.
The other way I prefer doing is to set a footer view. Something like this:
self.tableView.tableFooterView = UIView(frame: CGRect.zero)
By setting a tableFooterView the last cell would show a separator.

Related

Autolayout is ignored in custom TableViewCell

I'm trying to constrain some objects in my tableview cell so that they will be formatted correctly and won't clip on different devices. But, whenever I add a constraint to an object in there, it throws the object off screen to the top left. In the screenshot I attached I showed it with the green bar on the left but the same is true when I do it to the other labels and text fields.
Any ideas as to what I'm doing wrong?
I have a near identical table view that gets its data from another source and have them constrained the same way, but that tableview cell is formatted correctly when I build it.
I am seeing things online about Tableview cell subclasses. Is there something else I am supposed to be implementing in order to get these to stay? I'm not sure why they are working on one of my tableviews but not the other.
I am having the same issue that is being seen here Autolayout is ignored in Custom UITableViewCell but her answer is confusing me and I can't figure out how to reproduce it
This is what it looks like when the app is built:
Figured it out. For anyone else who may have this problem in the future. You need to click on the content view in the Storyboard and go to the indemnity inspector. Then from there make sure the Class is set to the default of UIView and not the custom class of the TableView Cell.

Detail Label in "Left Detail" style cell text getting cut off- swift

I have a table view controller with a prototype cell with style "Left Detail."
-In my viewDidLoad() I have self.tableView.estimatedRowHeight = 40 and self.tableView.rowHeight = UITableViewAutomaticDimension like many solutions have said to do. However, when my detail label gets too big (like with the description cell), the cell doesn't grow with the text.
-I tried to reload the data in viewDidAppear(animated:) as well, but that didn't help.
-I don't have anything in my heightForRowAtIndex func right now, but have tried to set that too and it didn't fix my problem.
-I also tried cell.sizeToFit() in my cellForRowAtIndexPath after the cells are populated.
Am I missing something obvious? Or is there something in the "Left Detail" style that is restricting the cell height?
You're not missing anything obvious that I'm aware of, but likely running into an edge case involving the built-in cell style. There are a small number of issues with self-sizing where it mostly works for the built-in styles but can fail for certain cases.
This is a side-effect of how the built-in styles manage their labels and constraints differently from how it would be done for a custom cell style. If you examine the built-in cell's content view in the debugger, its constraints array is empty.
For one edge case, if one of the built-in labels was not needed for a cell, Apple optimizes it by completely removing that view from the cell. When that cell gets reused and the label needs to be added back in, the constraints don't get updated for that initial occurrence. It was possible to work around that particular issue by ensuring that both labels always have text, so the view never was removed.
You definitely should not need to include heightForRowAtIndexPath. You should remove that, then see if you can work around the built-in style issue within cellForRowAtIndexPath. If not, you may have to use a custom cell which mimics the Left Detail style.
Either way, I'd recommend submitting a bug report with a small sample project that illustrates that "Left Detail" issue, as Apple has fixed many of these issues and built-in style self-sizing has been far more usable.

iPhone 6 Plus show strange lines in UITableViewCell next to the accessoryView

I have a UITableView that is showing some strange thin grey lines next to the accessory view. This ONLY happens on the plus, no other iPhone shows this issue.
It seems to have something to do with the imageView that is assigned to the cell. Some images cause the line, others don't, seemingly based on their dimensions.
Has anyone else seen this or know how to get rid of it?
I experienced this when using a UITableView that was partially covered with an SWRevealViewController.
When the calculated value of the tableview width was a decimal number, artifact lines between the content of a UITableViewCell and the accessory view would appear.
The solution was to make sure that size calculations for the view were rounded to whole numbers.
It looks like that line is from the right edge of the cell's content view. I don't know how it works, but my solution was:
cell.backgroundColor = .clear

How do I make a UITableViewCell separator show up?

I'm having a similar problem to this question: UITableViewCell separator not showing up.
However, the proposed solutions don't work for me. Specifically, I've checked the following:
My UITableViewCell subclass does not override drawRect:.
I don't have a custom UITableView and, therefore, I'm not overriding layoutSubviews.
In Interface Builder, I have the Separator attribute of the Table View set to "Single Line".
I've tried programmatically setting tableView.separatorStyle to UITableViewCellSeparatorStyleSingleLine.
But still the separator line will now show up… Does anyone know of something else that could cause this behavior or have any ideas for how I might track down what is hiding/removing the separator line?
EDIT:
Well I feel silly… In trying to create the screenshot requested by valheru, I noticed that the lines ARE there, but are almost exactly the same color as the background, so I couldn't see them until the screenshot was blown up. I had suspected earlier that the separator color might be the issue, and I tried testing for that by setting the separator color to white (my background is almost black), but it turns out that there was some copy/pasted code that was programmatically resetting the color to the almost-invisible color.
Thanks valheru for leading me to the answer. :-)
Check the height of your table view's row and the height of the cell. Make sure that the row's height is not less than the cell's height.

Is the separator part of a UITableViewCell?

I've written a custom GridView (UIScrollView Subclass) and decided to use a standard UITableViewCells as Cells because they have all the functionality I need.
Everything works fine but I've noticed that sometimes I have a thin gray line at the top of a cell.
I actually thought that the UITableView handles the separators of the cells and they actually don't belong to a UITableViewCell but it seems to be that I'm wrong.
In fact I want to get rid of them but I don't know how.
Does anyone has experience with this or is the only way to make a custom cell class with the features of a UITableViewCell?
Here's a screenshot:
After some experimentation, try & error and subview iterating/checking I can tell that the separator is definitely part of an UITableViewCell. Thanks to #Valeriy Van.
The answer to my first question simply is: YES, the separator is
part of a UITableViewCell.
But it is strictly handled by the UITableView and is empty if it is not populated by the TableView.
Now to the lines in the image above:
These are not separators. They just look like that, such a damn coincidence.
They happen when the Graphics tries to draw something at subpixel-precise coordinates.
This can happen, when the coordinates and/or sizes (the frame) of an visible object (the layer of the view) are between two integer values and the GL tries to render it properly.
Due the "overprecise" frame, the Gl tries to interpolate to integer frames or just not round properly.
So it can happen, like in the picture above, that the first line is stretched or the y-coordinate wrong by one pixel.
This can also happen in a UITableView if you return "overprecise" values for cell-heights.
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Edited:
Below is a line from UITableView.h
#property(nonatomic) UITableViewCellSeparatorStyle separatorStyle; // default is UITableViewCellSeparatorStyleSingleLine
UITableViewCell, UITableView, UITableViewController designed to work together. And your problem is you try to use UITableViewCell separately. Logically, cells separator is not characteristic of a cell, it's characteristic of a table. That's why separatorStyle is property of UITableView, not UITableViewCell. Well, different approaches are possible, and Apple had chosen this. Look into UITableView.h for how many times 'separator' substring occurs there. Have a look into UITableViewCell.h: UITableViewCell has reference to UITableView. And UITableViewCell coded accurately enough not to crash if _tableView is nil. I think, if _tableView is nil, cell applies same defaults and draws itself with default separator.
What can you do to get rid of separator in you case? If you can't use UITableView in way it was designed, cheat in some way. Try to feed cell with some dumb tableview with properties you need.

Resources