码迷,mamicode.com
首页 > 其他好文 > 详细

swif tableview全选

时间:2017-01-05 16:34:02      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:tableview   实现   value   queue   led   view   scroll   osi   rri   

技术分享

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全选

标签:tableview   实现   value   queue   led   view   scroll   osi   rri   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!