UITableViewDataSource没有被调用

时间:2015-01-27 23:52:59

标签: swift ios7

我正在努力学习swift,这也是我的第一个编程语言。我正在尝试通过创建一个包含表格视图的应用程序来学习。我添加了一个表视图和表格单元格(myCell作为标识符)。表格单元格又有标签和文本字段。表格单元格的背景颜色也是黄色。

封装所有这些的视图控制器被挂钩到类showDetailViewController,如下所示。

class showDetailViewController:UIViewController, UITableViewDataSource, UITableViewDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

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

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell: TaskCell = tableView.dequeueReusableCellWithIdentifier("myCell") as TaskCell
        return cell
    }

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

    }

}

当我运行我的应用程序时,我希望在表视图中看到我的单元格被复制5次(部分中的单元格数量返回5),但是在调试时我意识到没有调用tableview委托类,因此问题就出现了。

有人可以帮我解决这个问题吗?

谢谢, 开发

1 个答案:

答案 0 :(得分:0)

将tableView添加为IBOutlet。然后,您应该将tableView的数据源设置为viewController。 self.tableView.dataSource = self。您还可以在Interface bulider中设置tableView的dataSource。

相关问题