簡體   English   中英

當我按一個附件類型刪除按鈕時,如何刪除一個UITableView單元格?

[英]How to delete a UITableView Cell when i press a accessoryType delete button?

我只有一個UItableview。 每個單元格在單元格的右邊都有一個typeType symbol(>),當我觸摸一個tableview單元格時,它將向我推送一個新的Viewcontroller。 這很簡單。

現在的問題是,我想在我的表格單元格中,當我在AccessoriesType符號旁邊觸摸TouchDragIn時,它將向我顯示一個附件按鈕(就像刪除按鈕一樣)。 當我按下刪除按鈕。 它將從表格​​視圖中刪除單元格。

您需要實現這兩個委托。

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

}

//覆蓋以支持編輯表格視圖。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
    NSArray *objects = [NSArray arrayWithObjects:indexPath, nil];
        [tableView deleteRowsAtIndexPaths:objects withRowAnimation:UITableViewRowAnimationRight];   
    }   
} 

希望這對您有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM