リストコントローラが空の場合、TableViewControllerにUIImageView、テキスト、リンクを含むビューを表示する必要があります。スウィフト - 複雑なビューを表示するストーリーボードで空のリストを表示する
私はあなたがこのコードをラベルに挿入することができます知っている:
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
}
しかし、私は別のViewControllerでストーリーボードに設計された複雑なビューを表示する必要があると思います。
私はこれを試してみました:
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
コンテナコントローラを使用すると、 –