【发布时间】:2021-04-01 18:18:53
【问题描述】:
我正在尝试在 XIB 文件中添加 tableView,但收到此错误:this class is not key value coding-compliant for the key tableView.。我以前从未使用过 XIB 文件,所以我不确定可能是什么问题
这就是我加载 XIB 的方式:
let scoresVC = UIViewController(nibName: "LiveScoresViewController", bundle: nil)
navigationController?.pushViewController(scoresVC, animated: true)
class LiveScoresViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
tableView.register(UINib(nibName: "LiveScoreCell", bundle: nil), forCellReuseIdentifier: "LiveScoreCell")
}
}
【问题讨论】:
-
你是如何加载 xib 的?您是否正在创建
LiveScoresViewController的实例?如果是这样,请向我们展示该代码。 -
我刚刚将它添加到问题中,在我添加 tableView 之前它也加载正常
标签: swift uitableview xib