swif tableview全选

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

}

}

时间: 2024-08-27 10:37:31

swif tableview全选的相关文章

自定义tableView全选、单选、多选删除Cell

继上一篇tableView编辑状态下的全选删除. 上一篇说的是tableView系统自带的删除(系统的全选删除 本人研究了好久 始终没有研究出来,也希望大家如果用的是系统的allowsMultipleSelectionDuringEditing这种删除 实现了全选删除,本人也求一份小demo),而这篇里主要是自定义的全选.单选.多选删除.先上效果图 起初自己写遇到了很大问题,不是能非常完美的实现这块功能,由于研发时间问题,最终也是参考了一个写好的demo,进行了一个修改,demo地址 这个dem

UITableView多选全选

自定义cell和取到相应的cell就行了 TableViewCell.h #import <UIKit/UIKit.h> @interface TableViewCell : UITableViewCell { BOOL _checked; UIImageView *_checkedImage; } - (void)setChecked:(BOOL)checked; @end TableViewCell.m #import "TableViewCell.h" @implem

UITabView/UICollectionView 全选问题

UITabView/UICollectionView 全选问题 SkySeraph July. 30th 2016 Email:[email protected] 更多精彩请直接访问SkySeraph个人站点:www.skyseraph.com The Issue Recently in my new project I need to select all the cell data in my UITabViewCell and UICollectionViewCell, and need

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

还是在上一个程序的基础上进行修改 1.反选按钮 2.全选按钮 3.删除按钮 4.其他代码优化 1.反选按钮 反选的过程就是将_deleteShops数组中得数据清空,然后将Shops中数组添加到_deleteShops数组 添加一个 UIBarButtonItem 按钮,绑定响应事件. 代码如下 1 // 反选 2 - (void)unSelected 3 { 4 // 1.记录shops数组的长度和_deleteShops的长度 5 NSInteger shopsCount = _shops.

UITableViewCell 多选和全选(checkBoxCell)

原文地址: http://www.cnblogs.com/hxwj/p/4532172.html 思路分析 前期准备:1.创建两个数组:一个是真正数据的不可变数组array,一个是自定义可变数组checkArray,(存储一个key对应array.count个value,值为NO). 2.给cell创建两个属性:一个用来存储多选或全选的状态,一个用来控制选中和未选中.   3.在cell中给外界暴露一个设置状态方法,然后根据外界传进来的状态来设置不同的图像状态. 一.全选 1.这里使用按钮的选中

iOS疯狂详解之UITableView的全选和多选功能

多选做法如下: - (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableViewdeselectRowAtIndexPath:indexPath animated:YES]; Custom *cell= (Custom*)[tableView cellForRowAtIndexPath:indexPath]; NSUIntegerrow = [indexP

反选,全选,删除按钮的实现

阅读目录 1.反选按钮 2.全选\全不选按钮 3.删除按钮 4.其他代码实现 还是在上一个程序的基础上进行修改 1.反选按钮 2.全选按钮 3.删除按钮 4.其他代码优化 回到顶部 1.反选按钮 反选的过程就是将_deleteShops数组中得数据清空,然后将Shops中数组添加到_deleteShops数组 添加一个 UIBarButtonItem 按钮,绑定响应事件. 代码如下 1 // 反选 2 - (void)unSelected 3 { 4 // 1.记录shops数组的长度和_del

jQuery学习(五)——使用JQ完成复选框的全选和全不选

1.在系统后台进行人员管理时,进行批量删除,使用jq完成全选和全不选 步骤分析: 第一步:引入jquery文件 第二步:书写页面加载函数 第三步:为上面的复选框绑定单击事件 第四步:将下面所有的复选框的选中状态设置成跟上面的一致! 2.具体代码实现: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>使用jQuery完成复选框的全选和全不

jq变态全选vs原生变态全选

<script> $(function(){ var num=0; $("#btn").on('click',function(){ if(this.checked){ $("#box").children().attr('checked',true); num=$("#box").children().length;//赋个值 }else{ $("#box").children().attr('checked',