2016-09-16 6 views
1

私はこれについて調査しましたが、まだ解決策が見つかっていないようです。カスタムUITableViewCell(ラジオボタン、ラベルなどを含むさまざまなサブビュー)があります。私は、テーブルビューが編集中に設定されているときに、セルの左端に+と - の挿入/削除編集コントロールを表示したいと思います。編集コントロールの挿入/削除がカスタムUITableViewCellの編集中に表示されない

標準のUITableViewCellを使用した場合、これは完全に機能します。しかし、カスタムセルを使用している間は、コントロールは表示されません。誰もが同じように修正する方法についての任意のアイデアがありますか?以下は

は....私のテーブルビューコードのいくつかのスナップショットです
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (self.isEditing) { 
     if ([tableView isEqual:self.tableView]) { 
      if (editingStyle == UITableViewCellEditingStyleInsert) { 
       // ... 
      }     
      else if (editingStyle == UITableViewCellEditingStyleDelete) { 
       // ... 
      } 
     } 
    } 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if ([tableView isEqual:self.tableView]) { 
     if (indexPath.row == 0) { 
      return UITableViewCellEditingStyleInsert; 
     } 
     else { 
      return UITableViewCellEditingStyleDelete; 
     } 
    } 
    else { 
     return UITableViewCellEditingStyleNone; 
    } 
} 

とカスタムテーブルビューセルコード

...

- (void)awakeFromNib 
{ 
    [super awakeFromNib]; 
} 

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [self setNeedsLayout]; 
} 

- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 

    [self configureConstraints]; 
} 

- (void)configureConstraints 
{ 
    // This is where the cell subviews are laid out. 
} 

答えて

3

カスタムセルでsetEditing:animated:メソッドを正しく実装しませんでした。あなたはsuperに電話をするのを忘れた:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 

    [self setNeedsLayout]; 
} 

それはあなたがsuperを呼び出さない珍しいオーバーライドされたメソッドです。

関連しない - テーブルビューコードでisEqual:を使用して2つのテーブルビューを比較しないでください。==を使用してください。

if (tableView == self.tableView) { 

実際に同じポインタであることを確認したいと思っています。

+1

ありがとう@rmaddy ...これは完全に動作します!スーパーミスでこの実装で私の監督!もう一度ありがとう - 私はちょうどちょうど最小時間の後に答えを受け入れるよ!コンパレータのチップもありがとう! – vikram17000

0

出典:Custom edit view in UITableViewCell while swipe left. Objective-C or Swift

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Clona" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){ 
     //insert your editAction here 
    }]; 
    editAction.backgroundColor = [UIColor blueColor]; 

    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){ 
     //insert your deleteAction here 
    }]; 
    deleteAction.backgroundColor = [UIColor redColor]; 
    return @[deleteAction,editAction]; 
} 
+0

ありがとう@ user6837640 ...これは実際には編集操作を表示しますが、左のスワイプにのみ表示されますか?私はテーブルが編集に設定されているときに+と - ボタンが常に表示されるようにします。基本的にiOSの連絡先を編集するようなものですか...何か迷っていますか? – vikram17000

+0

これは正しい解決策ではありません。 – rmaddy

関連する問題