Swift 未调用 UITableViewDelegate 方法

Swift UITableViewDelegate methods not being called

我创建了一个 ViewController 并使用 storyboard 添加了一个 TableView

我将 Storyboard 中的 Class 设置为 ViewController 到我的 NewsFeedViewController class。我将 tableview 插座的委托设置为 self。

class NewsFeedViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var newsFeedTableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        newsFeedTableView.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

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

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell =
        newsFeedTableView.dequeueReusableCellWithIdentifier(
            "newsFeedIphoneCell", forIndexPath: indexPath)
            as! NewsFeedIphoneTableViewCell

        return cell
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    }

}

当我 运行 时,委托方法的代码 none 被触发。我做错了什么?

您缺少数据源分配。

尝试添加

newsFeedTableView.dataSource = self

还有。