我们怎样才能隐藏tableHeaderView和tableFooterView? [英] How can we hide the tableHeaderView and tableFooterView?

查看:263
本文介绍了我们怎样才能隐藏tableHeaderView和tableFooterView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个按钮,我将它添加到表格页脚中,另一个添加到表格标题中,我知道如何使用此代码隐藏表格的标题视图 table.tableHeaderView.hidden =是;
但问题是表格的顶部仍然有空格。这个空间等于标题视图大小,但视图是隐藏的。它仍然有我们如何通过删除这个空格来禁用表头。我希望天才开发人员理解我的问题。请帮助我。
提前致谢。

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.

推荐答案

而不是隐藏你应该做的标题视图,

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;






在Swift中:


In Swift:

class myTableViewController: UITableViewController {

    @IBOutlet var tableHeaderView: UIView!

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

}

on你的故事板,只需将UIView拖入表格视图即可。它将神奇地成为表格视图标题(如果你再做一个,它将成为表格视图页脚)。 您必须点击标题视图,并拖动引用到表格视图控制器,然后链接它到tableHeaderView......那部分不是魔法。

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".

注意因为!在声明中,你必须记住在Storyboard上拖动链接,否则你会在测试过程中遇到运行时错误,所以这是一件好事。

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.

这篇关于我们怎样才能隐藏tableHeaderView和tableFooterView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆