首页 > 其他 > 详细

swif tableview全选

时间:2017-01-05 16:33:48      阅读:129      评论:0      收藏:0      [点我收藏+]

技术分享

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)!)!)

        }

    }

 

swif tableview全选

原文:http://www.cnblogs.com/caodedi-88/p/6252673.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!