简体   繁体   English

tableView(:cellForRowAtIndexPath :)未调用

[英]tableView(:cellForRowAtIndexPath:) Not Called

I know this question has been asked a million times, but I came across this problem and couldn't figure it out for the life of me, and all the previous examples only have unique code to their problem. 我知道这个问题已被问了一百万次,但是我遇到了这个问题并且无法弄明白我的生活,所有前面的例子只有他们问题的唯一代码。

I have a viewcontroller, inside of which I have a tableview. 我有一个viewcontroller,里面有一个tableview。 I created a custom tableviewcell class and my problem: The cellforrowatindexpath, which is set up in the viewcontroller isn't even called. 我创建了一个自定义tableviewcell类和我的问题:在viewcontroller中设置的cellforrowatindexpath甚至没有被调用。 I've included the UITableViewDataSource and UITableViewDelegate protocols, but no results - my tableview shows up without any of the configurations (mainly populating the cells). 我已经包含了UITableViewDataSource和UITableViewDelegate协议,但没有结果 - 我的tableview显示没有任何配置(主要是填充单元格)。

It's super simple, I just figured it out: 它非常简单,我只想出来:

Go to the storyboard, select the tableview and ctrl-drag to the yellow box at the top of the view controller (This is a reference to the view controller itself). 转到故事板,选择tableview并按住Ctrl键拖动到视图控制器顶部的黄色框(这是对视图控制器本身的引用)。 Then make sure to select both the delegate and datasource options (white dot to the left of the options indicates they're selected). 然后确保选择委托和数据源选项(选项左侧的白点表示它们已被选中)。

You can set the delegate properties in storyboards like you mention above but you can also set them in viewDidLoad using: 您可以像上面提到的那样在故事板中设置委托属性,但您也可以使用以下命令在viewDidLoad设置它们:

self.tableView.delegate = self
self.tableView.datasource = self

This will create the reference to the UITableViewDelegate and UITableViewDataSource 这将创建对UITableViewDelegateUITableViewDataSource的引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM