UITableView disable swipe to delete, but still have delete in Edit mode?

后端 未结 7 1895
面向向阳花
面向向阳花 2020-12-07 10:33

I want something similar as the Alarm app, where you can\'t swipe delete the row, but you can still delete the row in Edit mode.

When commented out tableView:commitE

7条回答
  •  醉梦人生
    2020-12-07 10:44

    On C#:

    I had the same issue where it was needed to enable/disable rows with Delete option on swipe. Multiple rows needed to be swiped left and get deleted, keep them in another colour. I achieved using this logic.

    [Export("tableView:canEditRowAtIndexPath:")]
    public bool CanEditRow(UITableView tableView, NSIndexPath indexPath)
    {
    
        if (deletedIndexes.Contains(indexPath.Row)){
            return false;
        }
        else{
            return true;
        }
    
    }
    

    Note that deletedIndexes are a list of indexes which are deleted from the table without duplicates. This code check whether a row is deleted, then it disables swipe or vice versa.

    The equivalent delegate function is Swift is canEditRowAtIndexPath.

提交回复
热议问题