2016-06-01 14 views
0

背景色が黒いセルがいくつかあるtableViewがあります。ナビゲーションバーの編集ボタンをタップすると、表示されている現在の白色ではなく、黒に並べ替えることができる領域の背景色を変更したいと思いますか?セルの編集中にTableViewCellの背景色を変更する

以下の機能を使用して編集ボタンを完了に変更できますが、セルの特定の領域を変更する方法がわかりません。私はこれを変更する場所だと感じますが、私はどのように表示していません。

override func setEditing (editing:Bool, animated:Bool) 
    { 
     super.setEditing(editing,animated:animated) 

     if (self.editing) { 

      self.editButton.title = "Done" 
      self.navigationItem.setHidesBackButton(true, animated: true) 

     } else { 

      self.editButton.title = "Edit" 
      self.navigationItem.setHidesBackButton(false, animated: false) 
     } 
    } 

これは私が言及しているもののイメージです。この「削除するスワイプ」モードでは

enter image description here

答えて

1
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.backgroundColor = [UIColor redColor]; 
} 

テーブルビューは任意の挿入、削除、および並べ替えコントロールを表示しません。このメソッドは、デリゲートにアプリケーションのユーザーインターフェイスを編集モードに調整する機会を与えます。

コメントに従って、ユーザーがセルを削除しないでイベントをキャプチャしますが、スワイプして編集モードを終了します。

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
     UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
     cell.backgroundColor = originalColor; 
} 
+0

これは、編集中のセルの背景色を変更する場合に機能します。均一な黒色を得るためにすべてのセルを変更する方法はありますか? – Gugulethu

+0

これを試してみましたが、これは編集中にtableViewのトップセルのうちの2つにしか作用しませんでした-func tableView(tableView:UITableView、editingStyleForRowAtIndexPath indexPath:NSIndexPath) - > UITableViewCellEditingStyle { tableView.cellForRowAtIndexPath(indexPath)?backgroundColor = UIColor .blackColor() return UITableViewCellEditingStyle.None } – Gugulethu

+0

私はそれを把握することができました。正しい方向に私を導いてくれてありがとう。 ;) – Gugulethu

0

それはすなわちcellForRowAtIndexPathが一様に黒に変更するための色を持ったコードでセルの背景色を設定することが判明した:このために、我々は以下のデリゲートを持っています。 私は元々UITableViewCell XIBファイルからこれを行っていました。

関連する問題