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. [LintCode] Scramble String 爬行字符串

    Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...

  2. php链接mysql数据库

    php连接数据库有三种方法,刚刚发现通过mysql_connect,mysql_query连接已被废弃,而现在推荐的是通过“面向对象方法”和“PDO方法”连接数据库. 而我在使用面向对象的方法连接时, ...

  3. Git基本命令行操作

    A. 新建Git仓库,创建新文件夹git init  B. 添加文件到git索引git add <filename>  --- 单个文件添加git add * --- 全部文件添加 C. ...

  4. 前端性能优化----yahoo前端性能团队总结的35条黄金定律

    转自 http://www.cnblogs.com/lei2007/archive/2013/08/16/3262897.html

  5. JAVA 线程同步异步简单实例

    package test; public class testThread { public static void main(String[] args) { Example example = n ...

  6. DEDECMS里面DEDE函数解析

    下面来解说下DEDECMS织梦CMS模板里面的函数说明 在文件include/inc_function.php里面 GetCurUrl() 获贴切前的脚本的URL GetAlabNum($str) 把 ...

  7. Web前端开发基础 第四课(盒代码模型)

    盒模型代码简写 还记得在讲盒模型时外边距(margin).内边距(padding)和边框(border)设置上下左右四个方向的边距是按照顺时针方向设置的:上右下左.具体应用在margin和paddin ...

  8. JS开发windows phone8.1系列之1

    http://msdn.microsoft.com/zh-cn/library/windows/apps/dn629638.aspx,要点: 1.了解项目结构:package.appxmanifest ...

  9. windows bat 批处理 !vm 合并快播文件

    今天简单的写了一个bat批处理文件 用来处理快播的p2p的文件,一般回事这样的目录 你可以下载如下代码 @echo off for /r %%a in (.) do ( echo %%a cd %%a ...

  10. Empire C:Basic 2

    作为人与计算机沟通的媒介,C语言给我们呈现了:printf.scanf.以及缓冲区. 1.printf("%d",a) %d:d是decimal base(十进制)的开头字母,意思 ...