无法隐藏UITableView Swift中的空单元格
我在一个快速的应用程序中使用UITableView,并使用我自己的自定义UITableViewCell。
当试图隐藏UITableView中的空单元格时,它仍然具有白色背景。
在UITableView下我有一个背景图像(UImageView)。
我已经试图隐藏这些单元格,实际上它们是隐藏的,但是我仍然有一个白色的背景,使用下面的代码:
override func viewDidLoad() { super.viewDidLoad() var tblView = UIView(frame: CGRect(x: 0,y: 0,width: 0,height: 0)) tblView.backgroundColor = UIColor.clearColor() tableView.tableFooterView = tblView var nipName=UINib(nibName: "CustomCell", bundle:nil) self.tableView.registerNib(nipName, forCellReuseIdentifier: "CustomCell") }
更清洁的解决scheme是:
tableView.tableFooterView = UIView(frame: CGRectZero)
没有别的是必要的。
这是解决scheme:
tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) tableView.tableFooterView?.isHidden = true tableView.backgroundColor = UIColor.clear
SWIFT 3
tableView.tableFooterView = UIView(frame:.zero)
这个问题的另一个更简单的解决scheme是为您的tableView设置图像的背景。如果您只需要为非数据单元格使用白色背景,则图像应该是纯白色,或者您可以为您的tableview背景设置自定义图像。所以数据与细胞将有正常的背景和非数据单元它将显示您的背景图像:
self.tableViewName.backgroundColor = UIColor (patternImage: UIImage(named: "imageName.jpg")!)
这些在Swift 3.0中都适用于我
方法 – 1
let footerView = UIView(frame: CGRect.zero) tableView.tableFooterView = footerView tableView.tableFooterView?.isHidden = true tableView.backgroundColor = UIColor.clear()
方法 – 2
tableView.tableFooterView = UIView(frame: CGRect.zero)
Swift 3 :最简单的方法
tableView.tableFooterView = UIView()