在我的视图控制器中,我使用UITableView,在每个自定义单元格中,我从不同的数组加载数据,现在如果特定单元格没有数据,则显示NO-Data,但现在如果每个单元格都没有数据,则我希望隐藏UITableView并显示No-Data图像。有人能帮帮我吗。
现在我想计算多个数组,检查它是否为空。但我认为这不是一个可行的解决方案。
谁有更好的解决方案?
发布于 2017-09-21 17:03:35
试试这个:-
if self.ary.count == 0 && self.ary1.count == 0 //multiple arrays
{
self.tableview.setBackgroundText(stringValue: "No Data")
}
extension UITableView {
func setBackgroundText(stringValue:String) {
let backgroundLabel = UILabel()
backgroundLabel.textColor = UIColor.blue
backgroundLabel.numberOfLines = 0
backgroundLabel.textAlignment = .center
backgroundLabel.text = stringValue
backgroundLabel.autoresizingMask = [.flexibleWidth, .flexibleHeight]
backgroundLabel.translatesAutoresizingMaskIntoConstraints = true
self.backgroundView = backgroundLabel
self.backgroundView?.backgroundColor = .red
}
func removeBackgroundText() {
self.backgroundView = nil
}
}https://stackoverflow.com/questions/46339093
复制相似问题