UITableView无法识别的选择器发送到实例

时间:2016-07-09 07:41:00

标签: ios swift

我对发生的事情感到困惑我正在编写关于收藏视图的教程,因为我对编程很新,我相信我做的一切都是正确的,但我得到了点击-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

这是教程: http://www.thorntech.com/2015/08/want-your-swift-app-to-scroll-in-two-directions-like-netflix-heres-how/

import UIKit

class ViewController: UIViewController, UITableViewDataSource {

var categories = ["Action", "Drama", "Science Fiction", "Kids", "Horror"]

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return categories[section]
}

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return categories.count
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! CategoryRow
    return cell
}

1 个答案:

答案 0 :(得分:7)

您是否使用storyboard或programmtically将Tableview委托设置为UITableViewDataSource。

将Tableview委托以程序方式设置为 UITableViewDataSource。

yourtableview.dataSource=self

使用storyboard set Tableview委托给UITableViewDataSource 显示在图片下方。

enter image description here

检查您是否将UITableViewDataSource设置为错误。