20

カスタム tableViewCell があります。強調表示してユーザーのタッチダウンを示したい。セル選択スタイルはUITableViewCellSelectionStyleBlue. 親コントローラーで設定しself.clearsSelectionOnViewWillAppear = YESました。

私は行く準備ができているはずです。いいえ。選択は引き続きセルに固定されます。私が欲しいのは、タッチダウン中だけの選択表示です。タッチアップすると、外観はすぐに選択されていない外観に戻ります。

どうすればいいですか?

乾杯、
ダグ

4

5 に答える 5

45
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}
于 2012-05-01T18:26:03.103 に答える
17

以下のSwiftの例ではdidHighlightRowAtIndexPath、タッチダウン時にセルの背景色を変更し、didUnhighlightRowAtIndexPath色をリセットするために使用しています-以下を参照してください:

// MARK: UITableViewDelegate

func tableView(tableView: UITableView, didHighlightRowAtIndexPath indexPath: NSIndexPath) {
  if let cell = tableView.cellForRowAtIndexPath(indexPath) {
     cell.backgroundColor = UIColor.greenColor()
  }
}

func tableView(tableView: UITableView, didUnhighlightRowAtIndexPath indexPath: NSIndexPath) {
  if let cell = tableView.cellForRowAtIndexPath(indexPath) {
     cell.backgroundColor = UIColor.blackColor()
  }
}
于 2015-05-14T06:09:53.533 に答える
1

- (void)setSelected:(BOOL)selected animate:(BOOL)animatedsuper を呼び出さずに上書きする

于 2012-05-01T17:55:58.650 に答える
-5

私は同じ問題を抱えていました。以下のコードは私にとって完璧に機能しました。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
于 2012-05-01T18:15:57.687 に答える