swif tableview全选

func selctAll() {

        idArr.removeAll()

        for var i = 0; i<sellingArr.count; i++ {

            let path: NSIndexPath = NSIndexPath(forRow: i, inSection: 0)

            self.tableView.selectRowAtIndexPath(path, animated: true, scrollPosition: UITableViewScrollPosition.None)

        }

    }

  //取消全选

    func cancelSelectAll() {

        for var i = 0; i < sellingArr.count; i++ {

            let path: NSIndexPath = NSIndexPath.init(forItem: i, inSection: 0)

            self.tableView.deselectRowAtIndexPath(path, animated: true)

        }

        tableView.setEditing(false, animated: true)

    }

//代理中除了要实现必须实现的代理以外有些需要注意的地方

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

    {

        let cell = tableView.dequeueReusableCellWithIdentifier(BSManagerBaseCellID) as! BSManagerTableViewCell

        cell.selectedBackgroundView = UIView()// 这句可以淡化选择时的颜色

        return cell

    }

    //编辑时写法,OC中写法相对简单,可以百度需要的OC的同学

    override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {

        return UITableViewCellEditingStyle(rawValue: UITableViewCellEditingStyle.Delete.rawValue | UITableViewCellEditingStyle.Insert.rawValue)!

    }

//选中时在这里操作

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        let path: NSIndexPath = NSIndexPath.init(forItem: indexPath.row, inSection: 0)

        let cell = tableView.cellForRowAtIndexPath(path) as! BSManagerTableViewCell

        if cell.selected == true {//如果是选中状态的话,我在这里的操作是把选中cell的id放在了一个数组中。

             idArr.append((sellingArr[indexPath.row]["id"] as? String)!)

        }

        

    }

    //取消选中的cell状态

    override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

        if isSelectStatus == true {//如果是选中状态的话,我在这里的操作是把选中cell的id从数组中移除。

            idArr.removeAtIndex(idArr.indexOf((sellingArr[indexPath.row]["id"] as? String)!)!)

        }

    }

 

转载于:https://www.cnblogs.com/caodedi-88/p/6252673.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值