-tableView:cellForRowAtIndexPath: 何时被调用?
我在 UITableViewController
中加载表格内容时遇到此问题。我创建了没有 xib 的 UITableViewController
。在 loadView 中,我调用一个函数来生成要显示的数据数组。我正在尝试从 tableView:cellForRowAtIndexPath:
中的数组加载单元格。但不知怎的,我什么也没得到。除此之外,当我为 about 调用设置断点时,它似乎没有被调用。谁能告诉我我在这里做错了什么吗?
I am having this issue with loading up table content in UITableViewController
. I have created UITableViewController
without the xib. In loadView
I am calling a function which generates the array of data to be displayed. And from that array in tableView:cellForRowAtIndexPath:
I am trying to load the cells. But somehow I am getting nothing on table. Besides that when I set break point for about call, it seems not get called. Can anyone tell what am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
-tableView:cellForRowAtIndexPath:
每当需要新单元格时都会被调用,无论是第一次用单元格填充屏幕时,还是当新单元格滚动到屏幕中时,但如果您没有,它永远不会被调用t 为表视图返回适当数量的节和行,因为默认情况下它们为 0。-tableView:cellForRowAtIndexPath:
gets called whenever new cell is needed, whether when first filling the screen with cells, or when a new cell is scrolled into the screen, but it will never get called if you haven't returned a proper number of sections and rows for your table view, as they will be 0 by default.cellforrowatindexpath 在建表时被调用。
您是否将表的委托设置为 self ?
你添加到你的.h了吗?
cellforrowatindexpath is called when building the table.
Have you set the delegate of the table to self?
Have you added to your .h?
正如 eimantas 所说,您必须使用 tableView:cellForRowAtIndexPath 方法设置 UITableView =(指向)yourClass 的“dataSource”委托...
这是每当需要新单元格时调用的方法(第一次看到您的表格时)创建所需数量的单元格以覆盖表格高度的整个高度),然后在用户滚动表格时调用它(不是创建新单元格,而是使用所需的新数据重用旧单元格)
as eimantas said, you have to set the "dataSource" delegate of your UITableView = (pointing to) yourClass with the tableView:cellForRowAtIndexPath method...
it's the method called whenever a new cell is needed (the first time you see your table it creates a needed number of cells to cover the whole height of your table height), then it's called when user scroll the table (not to create new cells, but to reuse the old cells with the new data needed)