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全选的更多相关文章

  1. 【iOS】UITabView/UICollectionView 全选问题

    UITabView/UICollectionView 全选问题 SkySeraph July. 30th 2016 Email:skyseraph00@163.com 更多精彩请直接访问SkySera ...

  2. UITableViewCell 多选和全选(checkBoxCell)

    思路1 一.全选 1.创建可变数组,存储所有未选中状态(NO)的布尔值按钮,点击时改变其状态,并传入按钮的状态. 二.多选 1.创建Cell时,从数组中取出相应的值,传给cell,如果为YES,否则为 ...

  3. UITableView多选全选

    自定义cell和取到相应的cell就行了 TableViewCell.h #import <UIKit/UIKit.h> @interface TableViewCell : UITabl ...

  4. IOS开发学习笔记029-反选、全选、删除按钮的实现

    还是在上一个程序的基础上进行修改 1.反选按钮 2.全选按钮 3.删除按钮 4.其他代码优化 1.反选按钮 反选的过程就是将_deleteShops数组中得数据清空,然后将Shops中数组添加到_de ...

  5. Jquery的点击事件,三句代码完成全选事件

    先来看一下Js和Jquery的点击事件 举两个简单的例子 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  6. 表格与ckeckbox的全选与单选

    先看看下面的效果: 用户点击头的checkbox时,所有表格数据行的checkbox全选或反选. 当数据行某一行没有选中时,头checkbox去选.当所有数据行的checkbox全选时,头的check ...

  7. jQuery全选、全不选、反选

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script sr ...

  8. java script第一篇(按钮全选的实现)

    今天刚学了java script,记录下学习新知识的点滴.以下是操作步骤.鉴于我是初级者,如有错误,恳请读者指正.万分谢谢. 1.新建一个文档(用NotePad软件,为了使得在浏览器中打开不是乱码,在 ...

  9. js动态获取子复选项并设计全选及提交

    在做项目的时候,会遇到根据父选项,动态的获取子选项,并列出多个复选框,提交时,把选中的合并成一个字符提交后台 本章将讲述如何通过js控制实现该操作: 1:设计父类别为radio,为每一个radio都加 ...

随机推荐

  1. Stereo Matching 立体匹配学习资料

    Middlebury Stereo Evaluation Camera Calibration and 3D Reconstruction OpenCV学习笔记(18)双目测距与三维重建的OpenCV ...

  2. [LintCode] Generate Parentheses 生成括号

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  3. Linux_初识

    一.什么是 Linux  ♦ 试说明 Unix 与 Linux 的历史 Multics 系统:由Bell(贝尔实验室).MIT(麻省理工学院)与GE(美国通用电器)合作开发的一个系统: 1969:K. ...

  4. JAVA List<> 合并去重

    List<A>和List<B>,A/B中均没有重复的,现在保证A/B合并为C,且C中没有重复的. 参考http://blog.csdn.net/secondjanuary/ar ...

  5. 2016HUAS暑假集训题1 H - N皇后问题

    Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上. 你的任务是,对于给定的N,求出有多少种合 ...

  6. Unity3D中C#和js方法相互调用

    通过查找资料,Unity3D中C#和js要相互调用彼此的方法,js文件必须放在"Standard Assets". "Pro Standard Assets" ...

  7. php课程---php使用PDO方法详解(转)

    本文详细分析了php使用PDO方法.分享给大家供大家参考.具体分析如下: PDO::exec:返回的是int类型,表示影响结果的条数. 代码如下: PDOStatement::execute 返回的是 ...

  8. 给RecyclerView实现的GridView加上HeaderView和FooterView

    给RecyclerView设置布局管理器 GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3); 写适配器,添加子项 ...

  9. nginx编译安装

    Nginx编译安装 1.nginx官网:http://wiki.nginx.org/Install下载:http://nginx.org/en/download.html 2.编译安装# wget h ...

  10. 类似网易新闻 title栏 滚动时 文字放大&变色

    http://files.cnblogs.com/files/n1ckyxu/ScrollTitleView.zip