2010-05-10 96 views
0

在描述问题之前,让我先指出这是一个与this question不同的问题。UITableViewCellSeparatorStyleNone在UITableView中选择时不隐藏蓝色分隔线

的问题

This screenshot是采取定在的tableView一休:didSelectRowAtIndexPath方法:和你可以在模拟器(最右边的图像)看到,还有在单个像素的蓝线所选单元格的底部。这不是客户要求的设计,也不是这个应用程序用来表现的行为:即使在选择时也不应该有分隔符。

我是怎么来的 我会使用自定义的UITableViewCell类与相应的笔尖(的.xib)文件最初设计此表视图,并与选择任何麻烦:根据需要分隔被隐藏。可以预见的是,由于视图层次结构的所有开销,滚动缓慢,因此我重新定制了自定义单元格以使用Loren Brichter的fast scrolling solution。现在滚动速度要快得多,但我无法摆脱我生命中的分隔符。

我已经试过

在上面的截图的时间...

  • 表视图在IB “分离器[无]”。
  • 包含表视图的UIViewController有这一行viewDid负载: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超类继承的方法。

回答

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

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

alt text http://files.me.com/mahboud/7k656q

看起来很熟吗?

你会如何解决这个问题?如果您不需要选择单元格,则禁用单元格选择。否则,如果您正在选择单元格,则应将该矩形设置得更大,以便在使用-drawConentRect中的自己的选择颜色进行绘制时,默认选择颜色不会显示。

+1

啊,谢谢Mahboud!我正在寻找我或苹果的原因,但它在ABTableViewCell中。评论这条线是不可能的! '// b.size.height - = 1; //为分隔线留下空间 – clozach 2010-05-13 15:47:52

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; 
    } 
+0

UITableViewCellSelectionStyleNone有副作用,使得我的绘图代码中的if语句从不计算为YES。 (请参阅上面的附加代码块。) 虽然我更喜欢在这里使用未经过修改的图形,但您的解决方案至少会以UITableViewCellSelectionStyleGray的形式提供较少突兀的选择重叠。谢谢,Manjunath! – clozach 2010-05-10 06:53:01