2016-07-09 232 views
0

我对正在发生的事情感到困惑我在收集视图上做了一个教程,因为我对编程相当陌生,而且我相信我做的一切都正确,但是我碰到了-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instanceUITableView无法识别的选择器发送到实例

这里是教程: 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 
} 

回答

3

你有没有用故事板设置泰伯维委托UITableViewDataSource或programmtically?

以编程方式将Tableview代理设置为UITableViewDataSource。

yourtableview.dataSource=self 

使用故事板

设置泰伯维委托UITableViewDataSource显示下面的图像。

enter image description here

或者

检查,如果你设置UITableViewDataSource错误的任何其他视图。

+0

它的工作!谢谢我将我的数据源直接设置为tableview而不是视图控制器 – Hightower98

+0

最受欢迎的兄弟 –

相关问题