2012-01-21 14 views

答えて

2

私は、あなたがのUITableViewCellのサブクラスを作成し、プロパティとしてボタンを追加することをお勧めその後、YESに自分hiddenプロパティを設定します。

@interface CustomCell: UITableViewCell 
{ 
    UIButton *btn1; 
    UIButton *btn2; 
} 

@property (nonatomic, readonly) UIButon *btn1; 
@property (nonatomic, readonly) UIButon *btn2; 

- (void)showButtons; 
- (void)hideButtons; 

@end 

@implementation CustomCell 

@synthesize btn1, btn2; 

- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStrig *)reuseId 
{ 
    if ((self = [super initWithStyle:style reuseidentifier:reuseId])) 
    { 
     btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     // etc. etc. 
    } 
    return self; 
} 

- (void) hideButtons 
{ 
    self.btn1.hidden = YES; 
    self.btn2.hidden = YES; 
} 

- (void) showButtons 
{ 
    self.btn1.hidden = NO; 
    self.btn2.hidden = NO; 
} 

@end 

そして、あなたのUITableViewDelegateに:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [(CustomCell *)[tableView cellForRowAtIndexPath:indexPath] hideButtons]; 
} 

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [(CustomCell *)[tableView cellForRowAtIndexPath:indexPath] showButtons]; 
} 

はそれがお役に立てば幸いです。

+0

ありがとうございます@ H2CO3、私は単一のセルを更新するときに動作しますが、すべてのセルが編集モードになっているときにこのメソッドを適用する方法を考えていますか? ( "マイナス" ボタンは、すべての行に表示されたときに意味?) – Stan92

+0

私はボタンを非表示にするためにこれを見つけた: - (UITableViewCellEditingStyle)のtableView:(のUITableView *)のtableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { [(CustomCell *) [tableView cellForRowAtIndexPath:indexPath] hideButtons]; return UITableViewCellEditingStyleDelete; } 編集モードを終了したときに表示されることはわかりません。 – Stan92

+0

とにかく、このメソッドは、セルを更新するときに呼び出されません。他のデリゲートメソッドの中で呼び出されます。 –

2

もっと簡単な解決策でこのスレッドを更新したかっただけです。あなたが親UITableViewさん-setEditing:animated:メソッドを呼び出した後、これは、セルごとに自動的に呼び出されます

override func setEditing(editing: Bool, animated: Bool) { 
    super.setEditing(editing, animated: animated) 
    // Customize the cell's elements for both edit & non-edit mode 
    self.button1.hidden = editing 
    self.button2.hidden = editing 
} 

UITableViewCellのカスタムサブクラス内の特定の要素を非表示にするためには、単にUITableViewCell(スウィフトで実装)ための1つの方法をオーバーライドします。

関連する問題