Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
666 views
in Technique[技术] by (71.8m points)

iphone - How can we hide the tableHeaderView and tableFooterView?

I have two buttons which i add it in one in table-footer and other one in table-header,i know how to hide the headerview of the table using this codetable.tableHeaderView.hidden = YES; but the problem is there is still space in the top portion of the table.That space is equal to the header-view size,but the view is hidden .It still has the space.How can we disable the table-header by removing this space.I hope you genius developers understand my question.Please help me. Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Instead of hiding the header view you should do,

tableView.tableHeaderView = nil

And later if you want to show it then just assign it again,

tableView.tableHeaderView = tableHeaderView;

In Swift:

class myTableViewController: UITableViewController {

    @IBOutlet var tableHeaderView: UIView!

    private func toggleHeaderView() {
        if tableView.tableHeaderView == nil {
            tableView.tableHeaderView = tableHeaderView 
        } else { 
            tableView.tableHeaderView = nil 
        }
    }

}

on your Storyboard, simply drag a UIView in to the table view. It will "magically" become the table view header (if you do another one, it will become the table view footer). HOWEVER you must click on that header view, and drag the referencing outlet to the table view controller, and link it to "tableHeaderView" ... that part is not "magic".

Note that because of the "!" in the declaration, you have to remember to drag the link on Storyboard or you'll get a runtime error during testing, so that's a good thing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...