Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView';滚动后s单元格分隔符消失_Ios_Uitableview - Fatal编程技术网

Ios UITableView';滚动后s单元格分隔符消失

Ios UITableView';滚动后s单元格分隔符消失,ios,uitableview,Ios,Uitableview,我将UITableView配置为“UITableViewStylePlain”,其分隔符样式为UITableViewCellSeparatorStyleSingleLine。这些单元格具有背景色 问题是,当您滚动tableview时,一旦一些单元格从屏幕上消失并返回,分隔符就不再可见 这些单元格注册于: [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier]; 单元代码: - (void)customizeMyTabl

我将UITableView配置为“UITableViewStylePlain”,其分隔符样式为UITableViewCellSeparatorStyleSingleLine。这些单元格具有背景色

问题是,当您滚动tableview时,一旦一些单元格从屏幕上消失并返回,分隔符就不再可见

这些单元格注册于:

[tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
单元代码:

- (void)customizeMyTable
{
    [self.tableView setDataSource:self];
    [self.tableView setDelegate:self];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

    NSString *cellIdentifier = [MyTableViewCell cellIdentifier];
    UINib *nib = [UINib nibWithNibName:cellIdentifier bundle:nil];

    [self.tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
    self.tableView.rowHeight = 50;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyTableViewCell *cell = (MyTableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellID];

    [cell configure:someDataForThisRow];

    return cell;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor lightGrayColor];
}

有人遇到过这个问题吗?这似乎只发生在iOS 5上,而不是在iOS 6表视图上。

如果在自定义单元格中实现了布局子视图,并且意外忘记调用相应的超级方法,则将看不到分隔线

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cellView = tableView.dequeueReusableCell(withIdentifier: cellReuseId, for: indexPath)
    cellView.clipsToBounds = true //Add this line
    return cellView
}
也许你应该检查一下你是否忘记在其他方法中调用super

- (void)layoutSubviews
{
    [super layoutSubviews]; //<-THIS LINE YOU NEED

    //own code continues here
}
-(无效)布局子视图
{

[超级布局子视图]我必须将分隔符插入设置为0才能停止问题。

通过将分隔符插入值设置为0,我的问题也得到了解决。

这与LED屏幕分辨率有关,因为实际设备的分辨率非常高,显示器发现很难在屏幕上显示这些细线。它在实际设备上工作正常。
有人告诉我不要管它。因此,如果问题只存在于模拟器上,那么你可以接受这个问题。

如果它让你感到厌烦,那么制作一个自定义单元格,在其中放置一个分隔符,并通过 对于Obj.C: [self.tableView setSeparatorStyle:uitableviewCellseparatorstyle]


否则,当您在真实设备上进行测试时,您应该不会有问题。

我在swif中也有同样的问题。在我的例子中,我通过单击“按视图层次结构调试”按钮,发现滚动时新出现的单元格与其他单元格有一点重叠。这就是分隔线消失的原因。 因此,解决方案非常简单,请在cellForRowAtIndexPath clipsToBounds=true中设置单元格返回,使其不会超出指定的高度,并与另一个单元格的分隔线重叠

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cellView = tableView.dequeueReusableCell(withIdentifier: cellReuseId, for: indexPath)
    cellView.clipsToBounds = true //Add this line
    return cellView
}

如果动态生成UITableViewCell的内容,请确保将子视图添加到contentView,而不是添加到self:

contentView.addSubview(子视图)

而不是


self.addSubview(subView)

显示tableview的委托。-(UITableViewCell*)cellForRowAtIndexPath:(NSIndexPath*)InExpath确保tableview的行高与单元格的精确高度一致,或者单元格高度与rowHeight函数(在委托中)中返回的高度一致我也面临着同样的问题。你找到了一个解决方案吗?这里没有一个解决办法。我在iOS的所有版本上都面临这个问题。丢失或出现两个分隔符。但我发现这是因为,我使用的自定义单元格有一个背景色为灰色的容器视图。因此我将其修改为白色。因此,也请检查自定义单元格的内容及其属性。这对我刚才起作用。上一个单元格之前的单元格(屏幕外)没有分隔符,当视图被回收时,其他单元格丢失了分隔符。(我稍微说明了我的问题是什么,因为分隔符似乎有很多问题/解决方法)谢谢,这对我很有帮助