Add empty (empty) space under (at the end) UITableView

My application has UITableViewone that has a variable number of cells inside. How can I add empty (empty) space with a certain height below UITableView? Or at the very end UITableView? So after the very last cell there will be more free space.

+21
source share
8 answers

Make the contents tab in the form of a table:

let insets = UIEdgeInsets(top: 0, left: 0, bottom: 100, right: 0)
self.tableView.contentInset = insets

After you move to the last cell, you will leave an empty space under the table view.

+59
source

You can use tableView Footerfor this

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 100)];
[self.tableView setTableFooterView:view];
+8
source

2019. , :

viewDidLoad

tableView.contentInset.bottom = 100

, , .

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.contentInset.bottom = 100
}
+2

, (, ).

, , , tableView(_:heightForFooterInSection:) tableView:

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    if section == lastSectionIndex {
        return 30.0
    }
    return 0.001
}

0.001 , , , ; , . .

+1

:

: tableView. , scrolling-and-not-having-enough-bottom-space-causing-up-and-down-jumping-of-your-cells effect (.. - ).

cellHeight ( , cellHeight )...

. tableView-footerView , footerView :

let rowHeight = 70  // or whatever...
let nrOfCellHeightsSpaces = 6  // or whatever.. (consider scrolling !)
let heightDependentSpace = nrOfCellHeightsSpaces * rowHeight
let customViewFooter = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: heightDependentSpace))
customViewFooter.backgroundColor = .clear  // or whatever color
// add whatever customization of your extra bottom-space
// (such as copyrights, decent logos, product information, etc, etc)
tableView.tableFooterView = customViewFooter
0

.

0

@Siklab.ph .

self.tableView.contentInset.bottom = 100
0

I had some problems using it footerViewwhen using it together with sections before, so here is another approach that worked for me, you can also try creating a custom cellone that is just emptyViewshowing what exactly cellin the last index.

In numberOfRowsInSectionjust make the total number of lines more than the total number of lines you want to show.

And in cellForRowAtIndexPathyou can do something like:

if(indexPath.row == size + 1){
     //show custom cell
}
-2
source

Source: https://habr.com/ru/post/1651401/


All Articles