0

在描述这个问题之前,让我首先指出,这是一个与这个问题不同的问题

问题

此屏幕截图是在 tableView:didSelectRowAtIndexPath: 处设置中断时截取的,正如您在模拟器中看到的(图像的最右侧),在所选单元格的底部有一条单像素蓝线。这不是客户要求的设计,也不是这个应用程序过去的行为方式:不应该有分隔符,即使在选择时也是如此。

我是如何到达这里的 我最初使用带有相应 nib (.xib) 文件的自定义 UITableViewCell 类设计了这个表格视图,并且在选择时没有遇到任何问题:分隔符根据需要隐藏。可以预见的是,由于视图层次结构的所有开销,滚动很慢,所以我重新设计了自定义单元格以使用 Loren Brichter 的快速滚动解决方案。现在滚动速度要快得多,但我一生都无法摆脱分隔符。

我试过的

在上面的屏幕截图时...

  • 表视图在 IB 中有“分隔符 [无]”。
  • 包含表格视图的 UIViewController 在 vi​​ewDid 加载中有这一行:self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

正如您在屏幕截图中看到的那样,我插入了一些未使用的行来证明 separatorStyle 已按需要设置。其他测试确认 tableView 和 self.tableView 是同一断点处的等效指针。

我还尝试将 tableView.separatorColor 设置为黑色并清除,所有结果都相同:在进行选择之前,单元格看起来是正确的。


Manjunath:这是我用来绘制替代背景的代码,具体取决于单元格是否被触摸。您可以在屏幕截图中看到差异(动画时不那么微妙)。

if(self.highlighted) {
    textColor = [UIColor blackColor];
    UIImage *bg = [UIImage imageNamed:@"image-cell-background_highlighted.png"];
    [bg drawAtPoint:CGPointMake(0.0, 1.0)];
}
else {
    UIImage *bg = [UIImage imageNamed:@"image-cell-background.png"];
    [bg drawAtPoint:CGPointMake(0.0, 0.0)];
}

这在 UIImageCell.m 中被调用drawContentView:,该方法继承自 Brichter 先生的 ABTableViewCell 超类。

4

2 回答 2

2

克里斯,

深入研究 ABTableViewCell,我看到:

- (void)setFrame:(CGRect)f
{
 [super setFrame:f];
 CGRect b = [self bounds];
 b.size.height -= 1; // leave room for the seperator line
 [contentView setFrame:b];
}

由于单元格的高度比实际单元格短一个像素,因此当单元格被选中时,该一像素线将渗入选择颜色的颜色。它可能看起来像是分隔符,但实际上是选择颜色。

要进行测试,请尝试将上面的那条线更改为两个像素或更短,看看会发生什么。

更新:

通过对 FastScrollingExample 项目进行此更改-rootViewController

- (void)viewDidLoad
{
 self.title = @"Fast Scrolling Example";
 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [super viewDidLoad];
}

并注释掉:

// if(self.selected)
// {
//  backgroundColor = [UIColor clearColor];
//  textColor = [UIColor whiteColor];
// }
// 

-drawContentView模仿如果你没有显示选择颜色会发生什么,然后我得到一个这样的屏幕截图:

替代文字 http://files.me.com/mahboud/7k656q

看起来熟悉?

你将如何解决这个问题?如果您不需要选择单元格,则禁用单元格选择。否则,如果您正在选择单元格,那么您应该使矩形更大,这样当您使用自己的选择颜色在-drawConentRect.

于 2010-05-13T07:05:35.150 回答
1

试试这个: [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

 // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {

        static NSString *CellIdentifier = NSLocalizedString(@"Cell",@"");
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (nil == cell)
        {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        }   
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return cell;
    }
于 2010-05-10T04:58:24.577 回答