[英]How to delete a UITableView Cell when i press a accessoryType delete button?
I have just a UItableview. 我只有一个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.
每个单元格在单元格的右边都有一个typeType symbol(>),当我触摸一个tableview单元格时,它将向我推送一个新的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). 现在的问题是,我想在我的表格单元格中,当我在AccessoriesType符号旁边触摸TouchDragIn时,它将向我显示一个附件按钮(就像删除按钮一样)。 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.. 希望这对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.