[UIViewController中的tableView:numberOfRowsInSection:]:无法识别的选择发送到实例
问题描述:
我有一个连接到某些项的TabBar视图。[UIViewController中的tableView:numberOfRowsInSection:]:无法识别的选择发送到实例
我想,这些项目中的一个包含TableView
,但我不希望使用TableViewController
,因为我希望把别的东西在页面的头部。
我ViewController
实现2个协议UITableViewDataSource
和UITableViewDelegate
并包含以下功能:
func tableView(_ tableView: UITableView, numberOfRowsInSection
section: Int) ->
Int {
// Return the number of rows in the section.
return annunci.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath:
IndexPath) ->
UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier:
cellIdentifier, for: indexPath)
// Configure the cell...
cell.textLabel?.text = annunci[indexPath.row]
return cell }
然后,从故事板我添加具有标识符“小区”的原型细胞和链接的tableView
到viewController
作为数据源和代表。
当我运行程序的时候是好的,但是当我选择包含表查看应用程序的项目将引发此异常:
*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[UIViewController
tableView:numberOfRowsInSection:
unrecognized selector sent to instance 0x101c29370'
我怎样才能把东西在页面的顶部,然后在的tableView或者我怎样才能解决这个问题?
我使用的斯威夫特3的Xcode 8.2.1
答
对我来说,是我忘了包括委托和数据源。
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { ... }
其他原因,在一个新的新项目see this minimal working version of a UITableView
.运行它,你的代码与它比较,以发现的bug。
+0
我在做同样的错误。谢谢 :) –
您是否在包含tableView(也是tableView的delegate和dataSource)的类中实现了这些方法? – jokeman
是的,我只有那个班级 –