当表格视图中没有数据时,我具有以下代码来显示标签:
let noDataLabel: UILabel = UILabel(frame: CGRect(x: 30, y: 30, width: tableView.bounds.size.width-60, height: tableView.bounds.size.height-60))
noDataLabel.numberOfLines = 0
var message = ""
if segmentedControl.selectedSegmentIndex == 1 {
message = "There are no active timers to display. \n\nGo back to the 'All' page to start a timer. If you have no timers, click the '+' button in the top right hand corner of the screen to add one."
}
else {
message = "There are no timers to display. Add a timer by clicking the '+' button in the top right hand corner of the screen."
}
noDataLabel.text = message
noDataLabel.textColor = UIColor.black
noDataLabel.textAlignment = .center
tableView.backgroundView = noDataLabel
tableView.separatorStyle = .none
但是,标签没有插入物。我该如何解决?