简体   繁体   中英

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

I have just a UItableview. Every cell has a accessoryType symbol(>) in the right of a cell and when i touch a tableview cell it push me a new Viewcontroller. Its simple.

Now problem is that, I want in my tableview cell, when i TouchDragInside the accessoryType symbol it will show me a accessory button(Just like delete Button). When i press the delete button. It will delete the cell from the tableview.

You need to implement these two delegate..

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

}

// Override to support editing the table view.

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

Hope this will work for you..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM