我有一个UITableView,在某些情况下为空是合法的。因此,与其显示应用程序的背景图像,我更希望在屏幕上打印一条友好的信息,例如:
此列表现在为空。
做这件事最简单的方法是什么?
发布于 2019-05-02 10:43:51
使用Swift 4.2
func numberOfSections(in tableView: UITableView) -> Int
{
var numOfSections: Int = 0
if self.medArray.count > 0
{
tableView.separatorStyle = .singleLine
numOfSections = 1
tableView.backgroundView = nil
}
else
{
let noDataLabel: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: tableView.bounds.size.width, height: tableView.bounds.size.height))
noDataLabel.text = "No Medicine available.Press + to add New Pills "
noDataLabel.textColor = UIColor.black
noDataLabel.textAlignment = .center
tableView.backgroundView = noDataLabel
tableView.separatorStyle = .none
}
return numOfSections
}https://stackoverflow.com/questions/15746745
复制相似问题