[英]How to delete a cell in UITableView by using custom button in cell?
[英]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.