My app has a tableview with separatorInset setting for all rows like this:
self.tableView.separatorInset.left = 0
self.tableView.separatorInset.right = 0
But when I ran my code, all of my rows have a separatorInset good except the first row like this:
How can I set separatorInset for all rows?
Related
I am trying to make a custom TableViewCell for a tableview, and the size is 414x350. The problem I am having is when table view get loaded all the sizes are squeezed and not right. I have tried all of the followings:
Assigning row height from code
tableView.estimatedRowHeight = 350
tableView.rowHeight = UITableView.automaticDimension
Assigning row height from storyboard in tableview window
Assigning row height from storyboard in tableviewcell window
The result is still the same. Any help is appreciated!
For any cell's automatic row dimension to be calculated properly, in your Storyboard you must have a direct line of vertical constraints between every item that goes all the way from the top to the bottom. If you set the constraints yourself, same thing applies.
Don't assign any row heights, except the estimated.
I'm displaying information fetched from a server on tableview. My tableview cell view has two vertical stackviews placed horizontally in a content view. Each stackview has 6 items and depending on data I'm hiding and showing the stackview item and setting the stackview and content view height depending on content of stackview visible items. This is all working fine and the tableview is also looking good.
Now I have a feature to delete tableview rows on swipe of a tableview row. So after deleting any row and reloading tableview cells, tableview cell height is not getting set and shrinks.
Can anyone help me with how do I update tableview height after each reload? I've tried all possible solutions but none of them worked to me.
Try the following, in your viewDidLoad set:
tableView.estimatedRowHeight = 60 // this is an estimation but try and get it close to what the actual height may be
tableView.rowHeight = UITableViewAutomaticDimension
Then in the tableView heightForRowAt indexPath return this:
return UITableViewAutomaticDimension
I want to set tableview cell height automatically to show the label completely without happening like that?
Any help?
There are 2 things that you need to do:
1st thing: Set AutoLayout for it.
2nd thing: implement these code:
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 100
You can see more from my project: https://github.com/khuong291/Yelp
I use a dynamic tableViewController. I implement the numberOfSection to return 4, and the numberOfRowInSection return 1. These are the only changes I made for the blank TableViewController. But when I run it on simulator, it shows multiple cells, which I expected to be only four cells. Why is that?
Note: If I change the height of each cell to let the screen only fit four cells at a time, it will work fine since it won't let be me scroll down. So I guess is the tableViewController always try to fill the screen no matter how many cell it should display?
Yes, the UITableView will always continue to fill the screen with 'empty' cells of the default row height. To prevent this, you could add the following code in viewDidLoad:
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
(For Swift, check #VictorSigler's answer.)
In Swift:
self.tableView.tableFooterView = UIView(frame: CGRect.zeroRect)
I've got a UITableView with a section index. My issue is that the section index adds a 15 pt right margin on all the cells, despite the fact that I've set cell.separatorInset = UIEdgeInsetsZero, cell.layoutMargins = UIEdgeInsetsZero, and cell.preservesSuperviewLayoutMargins = NO.
Inspecting the frame of the cells' content views over time, they appear to be covering the full table view horizontally in tableView:willDisplayCell:forRowAtIndexPath:, but are at some point changed to be 15 pts narrower (320 -> 305).
I would like to counteract this behavior (i.e., make the section index render on top of the cells' content views). Is there any official way to prevent the cells from shrinking due to a section index being present?
Section index does not change the layout of tableView or cell, by default it lays over the tableView. You just have to clear the default background color on section index using these 2 lines:
tableView.sectionIndexTrackingBackgroundColor = UIColor.clear
tableView.sectionIndexBackgroundColor = UIColor.clear
by using above lines, you will see your tableView section index as shown in screenshot:
Hope it helps!