UITableView显示的行数多于numberOfRowsInSection中指定的行数: [英] UITableView showing more rows than specified in numberOfRowsInSection:
问题描述
我希望我的tableView显示包含文本的6行,在本例中为Example。据我所知,我的 numberOfSectionsInTableView:
和 numberOfRowsInSection:
设置正确。请参阅下面的示例代码:
I want my tableView to show 6 rows with text in it, in this case "Example." As far as I can tell, I have my numberOfSectionsInTableView:
and numberOfRowsInSection:
set properly. See example code below:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// Return the number of rows in the section.
return 6;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"Example";
return cell;
}
问题是当你看到下面的图片显示不应该行的行t /不存在。
The problem is when you see the image below showing lines for rows that shouldn't/don't exist.
如何摆脱第6行显示的行?
How do I get rid of the lines showing past row 6?
推荐答案
普遍接受这样做的方法是添加一个框架大小为CGRectZero的页脚视图,如下所示:
The generally accepted way of doing this is to add a footer view with a frame size of CGRectZero, as such:
[tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]]
这是做什么告诉表那里是一个页脚,因此它停止显示分隔线。但是,由于页脚有一个CGRectZero作为其框架,所以没有任何内容显示,因此视觉效果是分隔符只是停止。
What this does is tell the table that there is a footer, and so it stops displaying separator lines. However, since the footer has a CGRectZero as its frame, nothing gets displayed, and so the visual effect is that the separators simply stop.
这篇关于UITableView显示的行数多于numberOfRowsInSection中指定的行数:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!