[英]How do i disable/enable edit button when user doesn't fully swipe to delete table view cell?
我有一個tableView,它允許通過滑動單元格或通過“編輯”按鈕進入編輯模式來刪除。 問題是,我不確定如何正確啟用/禁用編輯模式。 用戶開始滑動行時應將其禁用,並在“取消滑動”行后將其啟用。
目前,我在editStyleForRowAtIndexPath中禁用(返回delete),並在didEndEditingRowAtIndexPath中啟用。
問題是,如果用戶沒有完成滑動操作該怎么辦? 例如,它們開始滑動一行,但在完全滑動之前釋放(導致該行彈回並隱藏“刪除”按鈕)。 在這種情況下,didEndEditingRowAtIndexPath不會被調用。 半掃后如何確保表格可編輯?
這是您可以正常使用的另一種方法(退出或注釋:editingStyleForRowAtIndexPath和didEndEditingRowAtIndexPath。)。 而且,您只能執行以下操作:
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Configure delete action:
// First remove the delete data from you data source.
Put here you code, like this:
[self.theMutableArrayWithDataSourde removeObjectAtIndex:indexPath.row];
// Second remove the cell:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.