美文网首页
swift tableViewcell的可选性删除

swift tableViewcell的可选性删除

作者: 晓蜻蜓 | 来源:发表于2016-08-26 12:22 被阅读0次
  • 现在是可以删除当前账号的


    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()
    }

相关文章

网友评论

      本文标题:swift tableViewcell的可选性删除

      本文链接:https://www.haomeiwen.com/subject/gbfasttx.html