我正在关注本教程,当我使用其中提到的代码时,我得到了下面的图像1中显示的错误,我不知道为什么我得到这些错误,尽管我使用相同的代码
我用谷歌搜索了如何解决这个错误,有些帖子建议导入UKIT类,我这样做但错误仍然存在
请让我知道如何解决它
图片-1 :
答案 0 :(得分:0)
你拼错了UITableViewSource它实际上是UITableViewDataSource,
添加数据源方法
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = demoTableVIew.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "CELL NUMBER : \(indexPath.row)"
return cell
}
答案 1 :(得分:0)
使用UITableViewDataSource
代替UITableViewSource
并添加委托和数据源
//MARK: - Table Delegates
func numberOfSections(in tableView: UITableView) -> Int {
return 1;
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10;
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellId: NSString = "cellSearch"
let cell: customCell = tableView.dequeueReusableCell(withIdentifier: cellId as String)! as! customCell
return cell
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}