DZNEmptyDataSet未显示

问题描述 投票:1回答:1

我正在创建一个空表视图,我已将DZNEmptyDataSet添加到我的应用程序中。我的表视图显示了一个空的数组的内容。但是DZNEmptyDataSet没有显示出来。这是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.dataSource = self
    tableView.delegate = self
    tableView.emptyDataSetSource = self
    tableView.emptyDataSetDelegate = self
    tableView.tableFooterView = UIView()
}
var emptyStrings: [String] = []
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return emptyStrings.count
}



func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   let cell = tableView.dequeueReusableCell(withIdentifier: "newsIdentifier", for: indexPath)
        cell.textLabel?.text = emptyStrings[indexPath.row]
    return cell

}
swift tableview
1个回答
0
投票

你应该DZNEmotyDataset类。例如“Swift 4”;

    func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
        let str = "Empty Name"
        let attrs = [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: UIFontTextStyle.headline)]
        return NSAttributedString(string: str, attributes: attrs)
    }

    func description(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
        let str = "Empty Title"
        let attrs = [NSAttributedStringKey.font: UIFont.preferredFont(forTextStyle: UIFontTextStyle.body)]
        return NSAttributedString(string: str, attributes: attrs)
    }

    func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? {
        return UIImage(named: "emptyImage")
    }
© www.soinside.com 2019 - 2024. All rights reserved.