2011-05-25 18 views
0

我從表視圖刪除單元格,並實現刷卡刪除實現簡單刪除(紅色減號按鈕),下面的代碼我使用:如何在UITableViewCell中

#pragma mark - 
#pragma mark Table View Data Source Methods 

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

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewCellEditingStyleDelete; 
} 

//Updating the data-model array and deleting the row 
- (void)tableView:(UITableView *)tv commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // If row is deleted, remove it from the list. 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
      [self.tagsArray removeObjectAtIndex:indexPath.row]; 
     [self.addTagTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 

這讓我實現刷卡刪除,但我想簡單地減去紅色按鈕刪除,如何實現呢?

回答

3

您可以放置​​UIButton並將它連接到IBAction。在IBAction寫,所以你將能夠按照您的要求。

-(IBAction)editTableForDeletingRow 
{ 
     [addTagTableView setEditing:editing animated:YES]; 
} 
7
- (void)viewDidLoad { 
    self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 

使用此代碼,您的應用中有一個編輯按鈕。如果按下此按鈕,「紅色減號」會自動出現:)

相關問題