-tableView:cellForRowAtIndexPath:什么时候被调用? [英] when does -tableView:cellForRowAtIndexPath: get called?
问题描述
我在加载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?
推荐答案
-tableView:cellForRowAtIndexPath:
每当需要新单元格时(无论是第一次用单元格填充屏幕还是将新单元格滚动到屏幕中)都被调用如果您未为表格视图返回适当数量的节和行,则将永远不会调用该方法,因为默认情况下它们将为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.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [yourArray count];
}
这篇关于-tableView:cellForRowAtIndexPath:什么时候被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!