我有一個連接到某些項的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
您是否在包含tableView(也是tableView的delegate和dataSource)的類中實現了這些方法? – jokeman
是的,我只有那個班級 –