gpt4 book ai didi

ios - UITableView 分隔线被添加到节标题 View ,怎么办?

转载 作者:可可西里 更新时间:2023-11-01 03:58:11 25 4
gpt4 key购买 nike

我得到了一个包含两个部分的 TableView ,没有疯狂的代码,只有我的委托(delegate)方法。它工作得很好,就像我希望它工作一样。它应该看起来像这张截图:

enter image description here

现在的问题是:有时在将 scoll View 滚动或轻弹到边界时,会发生这种情况(如果您看不到:第二部分标题顶部有 1 或 1/2 像素的灰色,什么不是这样的):

enter image description here

那么,这是 iOS 7.1 还是 7.x 的错误?我没有为标题使用自定义 View 。有谁知道如何解决这个问题?

非常感谢您的反馈。

最佳答案

我遇到了同样的问题,我为此苦苦挣扎了几周,我解决它的方法是将 tableView 的 separatorStyle 设置为 UITableViewCellSeparatorStyleNone,并添加一个自定义 subview ,它是单元格的 contentView 的一行。

然后在您的 cellForRowAtIndexPath 方法中,隐藏该部分最后一个单元格的行 subview :

- (UIView *)lineView
{
// Your frame will vary.
UIView *colorLineView = [[UIView alloc]initWithFrame:CGRectMake(82, 67.5, 238, 0.5)];
colorLineView.backgroundColor = [UIColor blackColor];
return colorLineView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
static NSString *identifier = @"cellIdentifier";
UIView *lineView = [self lineView];

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.selectionStyle = UITableViewCellSelectionStyleDefault;

[cell.contentView addSubview:lineView];
}

if (indexPath.section == 0)
{
if (indexPath.row == keys.count -1)
{
lineView.hidden = YES;
}
}
return cell;
}

关于ios - UITableView 分隔线被添加到节标题 View ,怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22541043/

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