2012-01-31 26 views
2

iPhoneアプリを開発していますが、問題が1つあります。私はいくつかの編集可能な行(UITableViewスライドが編集可能な行で編集できない行Xcode iPhone

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{) 

と一つではない編集可能な行とのUITableViewを持っている。私は編集をクリックすると、編集可能な行が右に少しスライドさせ、それの左側にある赤い丸いボタンがあり、しかし、編集できない行はまったくスライドしません。右にスライドさせる方法はありますか?しかし、左に赤いボタンがない場合は、それは現時点では素晴らしいとは思えません。 this:

+0

カスタムセルを使用していますか、または組み込みセルをカスタマイズしていますか? – dasblinkenlight

答えて

1

tableViewのデフォルトの動作を変更することをお勧めしますか? しかし、本当にしたい場合は、たとえばインデントを使用する。

// Might be target of button 
- (void) setEditingMode 
{ 
    tableView.editing = YES; 
    [tableView reloadData]; 
} 

// Might be target of button 
- (void) resetEditingMode 
{ 
    tableView.editing = NO; 
    [tableView reloadData]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell* cell = ...; 
    .... 
    Boolean cellIsEditable = ...; 
    if(tableView.editing && !cellIsEditable) 
    { 
     cell.indentationWidth = ...; // (please experiment to find the exact value) 
     cell.indentationLevel = 1; 
    } 
    else 
    { 
     cell.indentationLevel = 0; 
    } 
} 
+0

ああ、申し訳ありません私はそれがグループ化されたtableViewだと忘れてしまった。しかし、これはテキストを右にスライドさせるだけですが、セルはまだフルサイズです:S – kjeldGr

+0

私は自分自身で問題を解決しました:)しかし、まだ助けてくれてありがとう!:) – kjeldGr

+0

@kjeldGr - 解決策は何ですか?あなたが望むならば、あなた自身の質問に答えることができます(投票数の下にあるチェックマークを使って答えとしてマークすることができます)ので、他人がこの質問に遭遇するのを助けます – Robotnik

0

UITableViewCellをサブクラス化し、編集不可能な行を自分でスライドします。

@interface MyHistoryTableViewCell : UITableViewCell 
@end 

@implementation MyHistoryTableViewCell : UITableViewCell 

#define CELL_SLIDE_WIDTH 32 // found empirically 
- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 
    if (self.editingStyle == UITableViewCellEditingStyleNone) { // not editable 
     CGRect frame = self.frame; 
     UITableView *tableView = ((UITableView *)(self.superview)); 
     if (tableView.editing) { // going to editing mode 
      frame.origin.x = CELL_SLIDE_WIDTH; 
      frame.size.width = tableView.frame.size.width - CELL_SLIDE_WIDTH; 
     } else { // ending editing 
      frame.origin.x = 0; 
      frame.size.width = tableView.frame.size.width; 
     } 
     [UIView animateWithDuration:0.3 animations:^{ // match the tableView slide duration 
      self.frame = frame; 
     }]; 
    } 
} 
@end 

あなたが(例えば、スライドさせてはならないボタン)セルの右側に固定する必要がサブビューを持っている場合は、また

mySubview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; // anchors to the right margin 

行う、あなたは時に創造的でなければなりませんサブビューのframe.origin.xを設定します。私は働いていたものが見つかるまで多くの価値を試しました(価値は私には意味がありません)。

関連する問題