セルを選択したときに灰色を変更するにはどうすればよいですか?

ユーザーが選択した行をクリックしたとき
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.contentView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
}
の色をカスタム テーブルビュー セル (UITableViewCell のサブクラス) で必要な色に設定selectedBackgroundViewします。
UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
[selectedBackgroundView setBackgroundColor:[UIColor redColor]]; // set color here
[self setSelectedBackgroundView:selectedBackgroundView];
[selectedBackgroundView release];
-tableView:cellForRowAtIndexPath:または、次の方法で構成できます。
//...
[cell setSelectedBackgroundView:selectedBackgroundView];
//...
デリゲートメソッドで背景色を変更するのはどうですか?
-(void)tableView:(UITableView *)tableView didSelectedRowAtIndexPath:(NSIndexPath *)indexPath
これを試して :
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
@Kjulyと@Selkieの回答に感謝します。私はそれがあなたの両方で動作するようにします。
selectedBackgroundViewの backgroundColor を最初に設定します。cell.textLabel.backgroundColorとで変更cell.contentView.backgroundColorしdidSelectedRowAtIndexPathます。ありがとうございました。