2012-02-26 5 views
1

次のコードでは、UITableViewCellのグラデーションの背景を作成しています。グラデーションが大きく出ました。しかし、行を選択しようとすると、青色の強調表示された行は表示されません。カスタムグラデーションコードを削除すると、選択した行のハイライトがうまく動作します。私はここで何が欠けているのか分かりません。どんな助けでも大歓迎です。UITableViewCellでカスタムグラデーションを使用すると、選択された行の背景が表示されない

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

static NSString *CellIdentifier = @"TimeTableViewCellList"; 

TimeTableViewCell *cell = (TimeTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (!cell) { 
    cell = [[[NSBundle mainBundle] loadNibNamed:@"TimeCell" owner:self options:nil] lastObject]; 
    //To create the cell gradient 

    UIColor *startColor = [UIColor whiteColor]; 
    UIColor *endColor = [UIColor colorWithRed:247.0/255.0 green:243.0/255.0 blue:238.0/255.0 alpha:1.0]; 
    CAGradientLayer *gradient = [CAGradientLayer layer]; 
    gradient.frame = cell.bounds; 
    gradient.colors = [NSArray arrayWithObjects:(id)[startColor CGColor], (id)[endColor CGColor], nil]; 
    [cell.layer insertSublayer:gradient atIndex:0]; 
} 

TimeEntry * entry = [[self getTimeEntriesBySection:indexPath.section] objectAtIndex:indexPath.row]; 

//..OTHER CELL VALUES SET HERE 

cell.selectionStyle = UITableViewCellSelectionStyleBlue; 


return cell; 
} 

答えて

0

グラデーションレイヤーが選択された効果を覆い隠してしまいます。

代わりにグラデーションレイヤーをcell.contentView.layerに追加してみてください。問題が解決しない場合は、レイヤーをあなたの細胞サブクラスのプロパティを作成し、ここでsetSelected:animated:

+0

cell.contentViewに追加することは役に立ちませんでした。ただし、あなたが提案したように、setSelected:animiated:メソッドをオーバーライドすると動作します。 – Rocky

1

のオーバーライドでその可視性を変更する必要があり@jtruton に以下のものをベースとしたソリューションは、細胞からの抜粋ですサブクラス

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
    [super setSelected:selected animated:animated]; 
    if (selected) { 
     self.theGradient.hidden = YES; 
    } else { 
     self.theGradient.hidden = NO; 

    } 
} 
+0

喜んで助けました。よくやった! – jrturton

関連する問題