我想做一些类似于应用程序时钟的事情。
我有一个动态加载的表格 View 。
当没有可用的项目时,我想添加一个带有文本消息的 View ,而不是空的表格 View 。
我使用了actionSheet来指示何时没有可用的项目,它可以工作,但我更喜欢显示带有文本消息的 View ,就像在应用程序时钟中一样。
您知道如何继续吗?
override func viewWillAppear(animated: Bool) {
// get the destinations data ...
if (destinations.count<1){
var myActionSheet: UIActionSheet = UIActionSheet()
let title: String = NSLocalizedString("DestinationsMsg", comment: "")
myActionSheet.title = title
myActionSheet.delegate = self;
myActionSheet.addButtonWithTitle("Cancel")
myActionSheet.addButtonWithTitle("Add a Destination")
myActionSheet.cancelButtonIndex = 0
myActionSheet.showInView(self.view)
}
super.viewWillAppear(true);
}
这就是解决方案,即使我对标签的位置并不完全满意。
else {
var bounds: CGRect = UIScreen.mainScreen().bounds
var width:CGFloat = bounds.size.width
var height:CGFloat = bounds.size.height
var view1 = UIView()
let label = UILabel(frame: CGRect(x: 0, y: height / 4, width: width, height: 40))
label.textColor = UIColor(red: 160/255, green: 160/255, blue: 160/255, alpha: 1.0)
label.font = UIFont.boldSystemFontOfSize(26.0)
label.textAlignment = NSTextAlignment.Center
label.text = "No Destination"
view1.addSubview(label)
tableView.tableHeaderView = view1
}
最佳答案
当没有要显示的行时,将表格 View 的 tableHeaderView
设置为您的占位符 View 。当有行要显示时,将 tableHeaderView
设置为 nil
。
关于ios - Swift 中没有项目时的 View 而不是 Tableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28745155/