uitableview的隐藏标题

发布于 2025-02-01 21:58:01 字数 337 浏览 3 评论 0原文

我有带有隐形标头的TableView。我已经尝试以下未能以:

tableview.tableheaderview = .init(帧:cgRect(x:0,y:0,width:0,height:0))

tableview。 ?。

tableheaderview

​https://youtu.be/lnhqn8wvxnk“ rel =“ nofollow noreferrer”>这是一个示例

,所以这是一个错误,还是我错过了某些东西?

I have TableView with invisible header. I already tried unsuccessfully to hide the header with:

tableView.tableHeaderView = .init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))

tableView.tableHeaderView?.removeFromSuperview()

tableView.tableHeaderView = nil

But I found out that if you call a multitask or manually change the theme to dark/light, this header disappears

Here is an example

So, is this a bug, or I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

昵称有卵用 2025-02-08 21:58:01

该代码正常工作

tableView.tableHeaderView = .init(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))

This code works perfectly

tableView.tableHeaderView = .init(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
梦明 2025-02-08 21:58:01

您也可以为表标头尝试一下

tableView.tableHeaderView = UIView(frame: .zero)

,如果您想隐藏截面的标题,则可以使用以下桌面委托方法来实现。

func tableView(_: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return nil
}

func tableView(_: UITableView, heightForHeaderInSection _: Int) -> CGFloat {
    return 0
}

You can try this for table header

tableView.tableHeaderView = UIView(frame: .zero)

Also if you want to hide header for section then you can achieve with below tableview delegate methods.

func tableView(_: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return nil
}

func tableView(_: UITableView, heightForHeaderInSection _: Int) -> CGFloat {
    return 0
}
旧人九事 2025-02-08 21:58:01

您可以不用框架使用

 tableView.tableHeaderView = UIView()

You can use without frame

 tableView.tableHeaderView = UIView()
著墨染雨君画夕 2025-02-08 21:58:01

这对我有用

var frame = CGRect.zero
frame.size.height = .leastNormalMagnitude
tableViewname.tableHeaderView = UIView(frame: frame)

this 将在单行中使用[@getMemd的答案]

This Works For me

var frame = CGRect.zero
frame.size.height = .leastNormalMagnitude
tableViewname.tableHeaderView = UIView(frame: frame)

also this will work in single line [answer by @getmemd]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文