2012-12-02 174 views
7

我有「輕掃刪除」功能TableViewCell。我想自定義刪除按鈕。 enter image description here自定義UITableView中的刪除按鈕

這是可能的,以及如何訪問刪除按鈕?

+1

嘗試這些http://stackoverflow.com/q/8603431/194544 http://stackoverflow.com/q/1615469/194544 – beryllium

+0

@beryllium所以你的建議是創建一個自定義單元格?但我已經建立了單元格,我寧願設置一個手勢識別器,然後將其作爲自定義單元格。 – Spire

+0

你想要刪除按鈕的動作,或者你需要更改刪除按鈕 –

回答

6

當用戶進行刷卡操作

只需將這個在您的CustomCell

- (void)willTransitionToState:(UITableViewCellStateMask)state 
    { 
     [super willTransitionToState:state]; 
     if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) 
     { 
      for (UIView *subview in self.subviews) 
      { 
       if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) 
       { 
        UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)]; 
        [deleteBtn setImage:[UIImage imageNamed:@"arrow_left_s11.png"]]; 
        [[subview.subviews objectAtIndex:0] addSubview:deleteBtn]; 
       } 
      } 
     } 
    } 

你不應該這個方法將被調用嘗試一下,你不應該改變蘋果的默認意見。

+0

我找到了另一種刪除方法,但是謝謝你的努力。我會在這方面受到教育,因爲我會爲另一個項目需要它。 thx **有一件事,我不使用自定義單元格,這就是爲什麼我需要有關如何更改DELETE外觀的信息,看起來像微調按鈕** – Spire

+0

它清楚地寫在問題 – Spire

+7

它不會在ios 7中工作 – Kiddo

-1

試試這個:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
    // Your Code 
    } 
} 
+0

好的,以及如何在'//你的代碼'部分調用刪除按鈕?我如何在'UIButtonTypeCustom'中改變它? – Spire

+0

這是Table的Built功能,所以你可以做任何你想做的事情,比如從數組中除去value- [idArray removeObjectAtIndex:indexPath.row]; 其中idArray是具有ids的NSMutableArray。最後通過調用[tableView reloaddata]重新加載你的表; tableView是你的表名。 –

+0

我編輯了我的評論 – Spire

12

如果您只需要更改按鈕的標題,則只需添加titleForDeleteConfirmationButtonForRowAtIndexPath方法。

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return @"NewButtonName"; 
} 
+0

對我來說這真是太棒了:)謝謝! – slboat