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. python--range()函数

    1: >>> range(10, 0, -1) [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] >>> range(10) [0, 1, 2, 3, ...

  2. python 之ConfigParser

    ConfigParser 简介ConfigParser是用来操作配置文件的模块. 说明:[**]为配置文件的section,基本格式为 [section] key = valueeg: [db] db ...

  3. border-radius 圆角半径

    CSS3属性之一:border-radius 语法: border-radius : none | <length>{1,4} [ / <length>{1,4} ]? 相关属 ...

  4. Mysql bench执行sql语句批量操作数据所遇到的问题

    一.错误 rror Code: 1175. You are using safe update mode and you tried to update a table without a WHERE ...

  5. Odoo 9 PDF不显示中文字体

    在Ubuntu中安装中文字体:    $ sudo apt-get install ttf-wqy-zenhei    $ sudo apt-get install ttf-wqy-microhei

  6. JAVA生成二维码图片代码

    首先需要导入 QRCode.jar 包 下载地址看这里   http://pan.baidu.com/s/1o6qRFqM import java.awt.Color;import java.awt. ...

  7. Daily Scrum 11.5

    今天成员全部到齐,对今天的工作进行了总结,并对明天的工作作了安排.由于先前分配的任务都已基本完成,要完成程序的三级优化是较为艰巨的任务.所以我们讨论决定,除PM外其他成员都投入到程序的优化和改进中去. ...

  8. JQuery类型转换

    来自:http://blog.csdn.net/kfanning/archive/2010/04/14/5485412.aspx 转换成数字 ECMAScript提供了两种把非数字的原始值转换成数字的 ...

  9. 【iCore3 双核心板_FPGA】实验十七:基于I2C总线的ARM与FPGA通信实验

    实验指导书及代码包下载: http://pan.baidu.com/s/1dFqddMp iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...

  10. Java虚拟机学习记录

    一.java平台无关性的基础 1.和各个平台有关的虚拟机: 2.和各个平台无关的中间语言(class文件). 二.虚拟机语言无关性的基础 1.class文件 三.java虚机机器中java程序的生命周 ...