OGeek|极客世界-中国程序员成长平台

标题: ios - Swift +隐藏或删除 UIView [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:02
标题: ios - Swift +隐藏或删除 UIView

我有UITableViewController,在它上面我放了一个UIView,里面有一个UICollectionView

当 collectionView 数据为空时,我想删除 UIView。我试过了:

self.collectionView.removeFromSuperview() 

self.collectionView.hidden = true

这些删除了 UIView 但我的 tableview 上方有一个空白区域。我怎样才能摆脱它?

编辑:添加了我的 Storyboard的照片。推荐 View 不在 tableviewheader 内。

enter image description here



Best Answer-推荐答案


看起来 Collection View 是一个表头 View (您在 Storyboard 中放置它的方式)。

如果数据为空,请尝试将其设置为 nil

self.tableView.tableHeaderView = nil

关于ios - Swift +隐藏或删除 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40567131/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4