how to remove the white space that appears below the uitableview - ios

As shown in the [figure]
when I scroll down to the end appears a large block with nothing, How to remove this and scroll the scroll only until the end of UiTableView content?
the following images describe the configuration of my uitableview in the storyboard:storyboar_one, storyboard_two, storyboard_three
this my viewDidLoad Method:
override func viewDidLoad() {
super.viewDidLoad();
tableView.dataSource = self
tableView.delegate = self
let nib: UINib = UINib(nibName: "ObrigacaoTableViewCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "reuseIdentifier")
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 150
}

Try self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Because the table thinks there is a footer to show, it doesn't display any cells beyond those you explicitly asked for therefore it shows up as a blank space.
Also make sure the bottom edge inset of UITableView is 0

To remove blank cells in the table keep the below code in viewDidLoad() method after estimatedHeight,
tableView.tableFooterView = UIView(frame: .zero)

Remove empty cells in UITableView
self.tableView.tableFooterView = UIView()

Related

TopPadding occurs when using XLPagerTabStrip and UITableView

SubViewController (a child of ViewController and IndicatorInfoProvider) is added using MainViewController (a child of ButtonBarPagerTabStripViewController) with NavigationBar added.
Padding does not occur even if you tap tabbutton, padding occurs on top when swipe.
animated gif 👇
override func viewDidLoad() {
super.viewDidLoad()
print("viewDidLoad")
// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.clear
//tableview
self.tableView.delegate = self
self.tableView.dataSource = self
self.tableView.backgroundView = nil
self.tableView.backgroundColor = UIColor.clear
//動的に高さを変更
self.tableView.estimatedRowHeight = 155
self.tableView.rowHeight = UITableViewAutomaticDimension
//indicator
self.tableView.showIndicator()
//loaddata
loadData(page:0)
}
I've encountered the same problem.
Open your storyboard and select the MainViewController. In the Attribute Inspector deselect the checkbox 'Adjust scroll view insets'
Are you using a UITableViewController as a childViewController? This issue seems to happen in this case.
To fix this, you should be setting automaticallyAdjustsScrollViewInsets = false and also having as childViewControllers only UIViewControllers with a UITableView inside, instead of UITableViewController.
Cheers

Remove UITableView separator line

I want to remove the line between 2 views. The line that separates 2 UITableViewCells:
I declared table view as following:
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
self.tableView.scrollEnabled = NO;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.estimatedRowHeight = 85.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
So i actually wrote - self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Why does it still exist?
Objective-C :
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Swift:
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
Swift 5.0 renamed it in :
self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
Apply the line in viewDidLoad() method.
If you want to do it from nib file, set the tableView's Separator property to None
For Swift 4:
tableView.separatorStyle = .none
For Swift 5 :
viewDidLoad(){
tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
}
For Objective-C :
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
or you can use interface builder instead
For more information
SeparatorStyle
Hide tableView separators using UI
Here you select TableView 'Separator' property as 'None'.
https://i.stack.imgur.com/8KyH5.png
You can use the following code because it will not remove the line separators of the sections.:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Your code here //
cell.separatorInset = UIEdgeInsetsMake(0.f, [UIScreen mainScreen].bounds.size.width, 0.f, 0.f);
}
My problem was when I add tableView trough code and I have separate func to show tableview and add it on mainView (slide from bottom) I needed to add this
tableView.separatorStyle = .none
in that func where tableView is added on mainView and constraint it.
In Swift 4.2 you can conveniently use dot notation on a tableView's separatorStyle. Like so:
tableView.separatorStyle = .none
As #gonsee point out:
"Setting separatorStyle seems to have no effect unless the table view is in the window's view hierarchy. If you have a table view on some UIView subclass"
You should set the seperatorStyle in viewDidAppear if you your table in UIView.
override func viewDidAppear(_ animated: Bool) {
self.contentView.documentTableView.separatorStyle = .none
}
In viewDidLoad add tableView.separatorStyle = .none
Example:
override func viewDidLoad() {
super.viewDidLoad()
...
self.tableView.separatorStyle = .none // <---
...
}
you can archive these things in different ways
you can also use this one line of code in viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView()
}
You can do it on a storyboard
set the code in viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
tableView.separatorStyle = .none
}
add this line
tableView.separatorStyle = .none

How do i get a UITableViewHeaderFooterView subclass to use resize with autolayout?

I'm using Nibs with my tableview for the header and cell
tableView.registerNib(UINib(nibName: "CategoryCell", bundle: nil), forCellReuseIdentifier: "catcell")
tableView.registerNib(UINib(nibName: "CategoryHeaderCell", bundle: nil), forHeaderFooterViewReuseIdentifier: "catheader")
and setting up autolayout in the storyboard. theres a label and uiswitch aligned to each side.
I'm not getting contstraint errors, before someone suggests Correct subclassing and autolayout of UITableViewHeaderFooterView as a solution.
The problem is that the header cell is not filling the tableview, while the normal cell is. You can see a shortened header view below.
in my header subclass, ive tried a few things but they dont work.
override func awakeFromNib() {
super.awakeFromNib()
.....
self.contentView.autoresizingMask = UIViewAutoresizing.FlexibleWidth
self.autoresizingMask = UIViewAutoresizing.FlexibleWidth // this doesnt help
self.setWidth(414)
self.contentView.setWidth(414) // none of these change the size
}

UISearchBar colliding cell contents in UITableView with sections

I have a UITableView in a UIViewController...
I'm using a UISearchController to give me a search bar and setting this to the table's header view. I'm also using sections in the UITableView. My problem is, on first presentation, the table header collides with the first cell...
After search bar has been activated once and then dismissed, the table renders as I expect it to...
The code code looks like...
override func viewDidLoad() {
super.viewDidLoad()
self.table.dataSource = self
self.table.delegate = self
self.table.tableHeaderView = self.searchController.searchBar
self.definesPresentationContext = true
self.searchController.searchBar.sizeToFit()
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.searchResultsUpdater = self
self.searchController.delegate = self
}
... and this style works fine in other tables which do not have sections.
For future users, setting the table rows to have automatic height fixed this problem...
self.table.estimatedRowHeight = 44
self.table.rowHeight = UITableViewAutomaticDimension

delete lines between UITableViewCells in UITableView

I've created an UITableView with UITableViewCell. Between the view cells there are grew lines. I want to delete these lines and don't want to show them, but I don't know how.
I work with Xcode 6.1 and Swift.
Here is a screenshot that displays my screen:
THX!
Using Objective-C, we have:
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
for Swift 3:
self.tableView.separatorStyle = .none
for Swift 2:
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
OR:
if you are using the InterfaceBuilder, you can set the tableView's Separator property to None
Within InterfaceBuilder you can set the Separator property to None or do it programmatically by setting the property separatorStyle of your table view to UITableViewCellSeparatorStyleNone.
Swift 3:
tableView.separatorStyle = UITableViewCellSeparatorStyle.none
You can do it from storyboard like this;
Swift 5 Programmatically
private func buildTableView() -> UITableView {
let tableView = UITableView()
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.separatorStyle = .none
return tableView
}
Swift 5 :
cell.selectionStyle = UITableViewCell.SelectionStyle.none
tableView.separatorStyle = .none
when initializing the tableview. It can be set or through the storyboard or nib
If you are setting up a lazy tableView, you may want to change the color to clear, seems like an Apple bug where sometimes the style is replaced on layout cycles.
private lazy var tableView: UITableView = {
let table = UITableView(frame: self.view.bounds, style: .insetGrouped)
table.separatorStyle = .none // <- HERE
table.separatorColor = .clear // <- HERE
table.delegate = self
table.dataSource = self
table.estimatedRowHeight = UITableView.automaticDimension
table.register(UITableView.self, forCellReuseIdentifier: "MyCell")
return table
}()

Resources