UITableView禁用滑动来删除,但仍然在编辑模式下删除? [英] UITableView disable swipe to delete, but still have delete in Edit mode?

查看:110
本文介绍了UITableView禁用滑动来删除,但仍然在编辑模式下删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要类似于闹钟应用程式,但您无法滑动删除该列,但仍可在编辑模式中删除该列。



out tableView:commitEditingStyle:forRowAtIndexPath :,我禁止滑动删除,并仍然有编辑模式下的删除按钮,但当我按删除按钮时会发生什么。

解决方案

好吧,结果很简单。这是我为了解决这个问题:



Objective-C

   - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{
// Detemine如果它在编辑模式
if .tableView.editing)
{
return UITableViewCellEditingStyleDelete;
}

return UITableViewCellEditingStyleNone;
}

Swift 2

  override func tableView(tableView:UITableView,editingStyleForRowAtIndexPath indexPath:NSIndexPath) - > UITableViewCellEditingStyle {
if tableView.editing {
return .Delete
}

return .None
}



Swift 3

  override func tableView(_ tableView:UITableView,editingStyleForRowAt indexPath:IndexPath) - > UITableViewCellEditingStyle {
if tableView.isEditing {
return .delete
}

return .none
}

您仍然需要实现 tableView:commitEditingStyle:forRowAtIndexPath:才能提交删除。 >

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:commitEditingStyle:forRowAtIndexPath:, I disabled the swipe to delete and still had Delete button in Edit mode, but what happens when I press the Delete button. What gets called?

解决方案

Ok, it turns out to be quite easy. This is what I did to solve this:

Objective-C

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Detemine if it's in editing mode
    if (self.tableView.editing)
    {
        return UITableViewCellEditingStyleDelete;
    }

    return UITableViewCellEditingStyleNone;
}

Swift 2

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
    if tableView.editing {
         return .Delete
    }

    return .None
}

Swift 3

override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    if tableView.isEditing {
        return .delete
    }

    return .none
}

You still need to implement tableView:commitEditingStyle:forRowAtIndexPath: to commit the deletion.

这篇关于UITableView禁用滑动来删除,但仍然在编辑模式下删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆