gpt4 book ai didi

iphone - UITableView 显示的行多于 numberOfRowsInSection : 中指定的行数

转载 作者:IT王子 更新时间:2023-10-29 07:47:05 24 4
gpt4 key购买 nike

我希望我的 tableView 显示 6 行,其中包含文本,在本例中为“Example”。据我所知,我的 numberOfSectionsInTableView: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;
}

问题是当您看到下图显示了不应该/不存在的行时。

enter image description here

如何去除第 6 行之后的线条?

最佳答案

generally accepted way这样做的目的是添加一个帧大小为 CGRectZero 的页脚 View ,如下所示:

[tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]]

这样做是告诉表格有页脚,因此它停止显示分隔线。但是,由于页脚的框架是 CGRectZero,因此不会显示任何内容,因此视觉效果是分隔符只是停止。

关于iphone - UITableView 显示的行多于 numberOfRowsInSection : 中指定的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10771563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com