我希望我的 tableView 显示 6 行,其中包含文本,在本例中为“示例”。据我所知,我有我的numberOfSectionsInTableView:
and numberOfRowsInSection:
设置正确。请参阅下面的示例代码:
- (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;
}
问题是当您看到下图显示不应该/不存在的行时。
如何去掉第 6 行之后显示的行?
The 普遍接受的方式 https://stackoverflow.com/questions/1633966/can-i-force-a-uitableview-to-hide-the-separator-between-empty-cells这样做的方法是添加一个帧大小为 CGRectZero 的页脚视图,如下所示:
[tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]]
它的作用是告诉表格有页脚,因此它停止显示分隔线。但是,由于页脚使用 CGRectZero 作为其框架,因此不会显示任何内容,因此视觉效果是分隔符只是停止了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)