複雜視圖我需要顯示一些的UIImageView,文本和鏈接查看我的TableViewController如果名單控制器是空的。斯威夫特 - 顯示的UITableViewController與空單,通過故事板
我知道你可以通過這個代碼中插入一個標籤:
func numberOfSections(in tableView: UITableView) -> Int
{
var numOfSections: Int = 0
if youHaveData
{
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 data available"
noDataLabel.textColor = UIColor.black
noDataLabel.textAlignment = .center
tableView.backgroundView = noDataLabel
tableView.separatorStyle = .none
}
return numOfSections
}
但我需要表現出複雜的視圖故事板設計,在不同的視圖控制器。
我試着用這樣的:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let emptyViewController = storyboard.instantiateViewController(withIdentifier :"empty_controller") as! EmptyViewController
tableView.backgroundView = emptyViewController.emptyView
凡emptyView以這種方式被定義
class EmptyViewController: UIViewController {
@IBOutlet weak var emptyView: UIView?
...
}
但它不工作,我看不到在表視圖如果列表是空的。
我該怎麼辦?
謝謝你很多
肯定的內容,但我想有一個不同的控制器,其中插入UI組件 – dayroma
集裝箱控制器,你可以有嵌入父控制器不同的控制器 –