2017-09-01 10 views
0

私はラベル、イメージ、背景色が赤のUIVIewを含むtableViewを持っています。セルが選択されているときにUIViewの背景色が消えないようにするにはどうすればよいですか?

これは、ラベル、画像と赤の背景色

This is a picture of a row in my tableView which displays a label, image and a UIView that has a red background colour

を有するのUIViewを表示しかし、私は、セルの背景色を選択するたびに、私のtableViewの行の画像であります私はそれを選択したときにUIViewのが消えて、私が見ることができるすべては、ラベルと画像

これは、同じ行である

This is the same row when I select it

セルが選択されるたびにビューの背景色が消えないようにする方法があるのだろうかと思っていました。

+1

cell.seletionStyleから抽出された= .noneのAURはhttps://stackoverflow.com/questions/30233468/disable-the-uitableview-highlighting-but-allow-the-selection-of-individual-参照してください。細胞 –

答えて

0

セル選択スタイルがデフォルトに設定されているため、UITableViewCellの選択スタイルをnoneに変更しています。

のObjective C:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

スウィフト3:

cell.selectionStyle = .none 

あなたがユーザに通知したい場合はindexpathオブジェクトのリストが含まれていNSArrayの性質を維持し、セルを選択しました。

委譲メソッドdidSelectRowAtIndexPathメソッドでNSArrayを更新します。 cellForRowAtIndexPath方法変更の背景色で

indexpathがdidSelectRowAtIndexPathに最後NSArray

に存在する場合、選択された行をリロード。

+0

ありがとう!しかし、ユーザーとのやりとりのために、ユーザーが選択したことをどのようにユーザーにフィードバックするのですか? –

0

はこれを試してみてください:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
     //Just add this below line didSelectRowAt 
     tableView.deselectRow(at: indexPath, animated: true) 

} 
0

それは少し良くです。私はMBProgressHUD/Demo

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ 
      [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
     }); 
    } 
関連する問題