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
Related
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()
Here is an image of the issue:
As you can see the text is highlighted (select all) was pressed, however, as you can see the text isn't actually highlighted.
I don't think it matters but this search bar isn't searching local data it's using Algolia.
My class in implementing UISearchBarDelegate the search bar is created in code not interface builder and the only method implemented is searchBarSearchButtonClicked which I can include code for, but I don't think it's needed. Additionally, this VC is inside a navigation controller
Code:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 135;
searchBar.placeholder = "Search"
searchBar.delegate = self
navigationItem.titleView = searchBar
tableView.delegate = self
tableView.dataSource = self
self.edgesForExtendedLayout = UIRectEdge()
self.extendedLayoutIncludesOpaqueBars = false
self.automaticallyAdjustsScrollViewInsets = false
}
The effect comes from a white selection color. You can change the selection color by assigning a color to the property tintColor of UISearchBar, or over the appearance for all search bars:
UISearchBar.appearance().tintColor = .black
I'm trying to add an UISearchController on top of an UITableView (not in it's header) and I created a placeholder view for it in storyboard with a height constraint of 44.
In the normal state it all works fine but when I add some scope button, those overlap my first UITableViewCell and I'm unable to find a solution for this. I tried to re-set the height constraint of my placeholder view but I don't find the right functions to place it and couldn't find the "right" animation so it still looks nice.
My UISearchController looks like this:
override func viewDidLoad() {
super.viewDidLoad()
self.searchController.searchResultsUpdater = self
self.searchController.hidesNavigationBarDuringPresentation = true
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.searchBar.searchBarStyle = .Default
self.searchController.searchBar.tintColor = UIColor.blueColor()
self.searchController.searchBar.delegate = self
self.searchController.searchBar.scopeButtonTitles = ["Test1", "Test2"]
self.searchController.searchBar.sizeToFit()
self.searchBarViewWrapper.addSubview(self.searchController.searchBar)
}
Here is a solution I found worked well. Add searchBar to tableHeaderView instead of your wrapper view:
searchController.searchBar.scopeButtonTitles = ["Test1", "Test2"]
tableView.tableHeaderView = searchController.searchBar
You can download the project to see in detail
http://www.raywenderlich.com/wp-content/uploads/2015/09/CandySearch.zip
I've noticed some strange behavior of UITablesViews inside a ViewController when said ViewController is embedded within a UINavigationController. The following is the code of a simple prototype for selecting different UITableViews to be shown in a scene excluding the methods for the TableView and selecting which view to show.
class ChooseTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var tableViewA: UITableView = UITableView()
var tableViewB: UITableView = UITableView()
var colors: [String] = ["red", "blue", "green"]
var shapes: [String] = ["triangle", "circle", "square"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tableViewA.frame = CGRectMake(0, 50, 320, 200)
tableViewA.delegate = self
tableViewA.dataSource = self
tableViewA.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cellTableViewA")
tableViewB.frame = CGRectMake(0, 50, 320, 200)
tableViewB.delegate = self
tableViewB.dataSource = self
tableViewB.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cellTableViewB")
self.view.addSubview(tableViewB)
self.view.addSubview(tableViewA)
tableViewB.hidden = true
let segmentSelectorLabels = ["one", "two"]
let segmentSelector = UISegmentedControl(items: segmentSelectorLabels)
segmentSelector.frame = CGRectMake(self.view.frame.width/2 - 50, self.view.frame.height - 100, 100, 40)
self.view.addSubview(segmentSelector)
segmentSelector.selectedSegmentIndex = 0
segmentSelector.addTarget(self, action: "chooseTable:", forControlEvents: .ValueChanged)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
...
}
and here are the results of when ChooseTableViewController is not embedded in a UINavigationController and when it is
Simulators results
In another project the behavior can be fixed by simply adding
let emptyView:UIView = UIView()
and
self.view.addSubiew(emptyView)
with emptyView being the first added subview. This is a hackney solution to having the UITableViews placed in their proper position. Any insight to this behavior is appreciated.
uncheck "Adjust Scroll View Insets" for the viewcontroller in the Attributes inspector or do it in code:
self.automaticallyAdjustsScrollViewInsets = NO; (Obj-C)
self.automaticallyAdjustsScrollViewInsets = false (Swift)
some more explanation:
if this property is set to YES / true the viewcontroller - as the name says - automatically adjusts the insets for the first scrollview in its view hierarchy. this can be helpful if your scrollview / tableview / textview / webview takes up the whole screen and parts of it are normally hidden by the statusbar / navigationbar / tabbar or toolbar. then those insets make your content appear below the top bars / above the bottom bars. this though only happens when the scrollview / ... is the TOP MOST subview in the view hierarchy (= the subview at index 0). to make things clearer i uploaded four examples:
property set to YES / true and two textviews in the view hierarchy (at index 0 and 1): as you can see the insets are only set for the first scrollview
property set to NO / false and two textviews in the view hierarchy (at index 0 and 1): as you can see no insets are set at all
property set to YES / true, a button (subview at index 0) and two textviews (at index 1 and 2): as you can see no insets are set at all although the property is YES / true. that is because no scrollview is the TOP MOST subview in the view hierarchy.
property set to YES / true an a textview in the view hierarchy at index 0 taking up the whole screen: as you can see although the textview takes up the whole screen (starts at 0,0) the text is not hidden by the status- / navigationbar because the viewcontroller automatically adjusted the textview's (scrollview's) inset.
i hope i could help making things a bit clearer. :)
Set table view's frame origin y-positions to 0. Find "Extended Edges" settings for this view controller in storyboard and turn off "Under Top Bars".
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