swift tableViewcell的可选性删除

  • 现在是可以删除当前账号的


    Paste_Image.png
  • 实现效果:可退出的账号不可以进行左滑编辑删除
    1.tableView中实现这个方法所有的cell都可以左滑删除
/**
     删除cell
     
     - parameter tableView:    <#tableView description#>
     - parameter editingStyle: <#editingStyle description#>
     - parameter indexPath:    <#indexPath description#>
     */
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle,
                   forRowAtIndexPath indexPath: NSIndexPath) {
            if editingStyle == UITableViewCellEditingStyle.Delete{
                //删除对应的cell ,并设置一个动画
                let deletedUser = userList.removeAtIndex(indexPath.row)
                self.tableView.deleteRowsAtIndexPaths([indexPath],
                      withRowAnimation: UITableViewRowAnimation.Automatic)
                //从数据库中删除
                let realmDB = RealmDBHelper.sharedInstance
                realmDB.delete(deletedUser)
                self.tableView.reloadData()
            }
    }

2.实现这个方法进行选择性实现左滑删除

//可编辑
    func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        if indexPath.section != 0{
            return true
        }
        return false
    }

3.改变删除title

//左滑删除标题
    func tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String? {
        return "移除".localized()
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容