iOS tableView编辑删除(单选 多选)
来源:互联网 发布:万德数据库学生版 编辑:程序博客网 时间:2024/05/17 06:19
viewDidload 添加
for (int i = 0; i <_reouseArray.count ; i++) {NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];[dictionary setValue:@"NO" forKey:[NSString stringWithFormat:@"%d", i]];[_contacts addObject:dictionary];}
cellForRow中进行赋值
NSMutableDictionary *dictionary = [_contacts objectAtIndex:[indexPath row]]; if ([[dictionary objectForKey:keyForChecked] isEqualToString:@"NO"]) { [dictionary setObject:@"NO" forKey:keyForChecked]; [_showMediaCell setChecked:NO]; }else { [dic_material setObject:@"YES" forKey:keyForChecked]; [_showMediaCell setChecked:YES]; }#define keyForChecked [NSString stringWithFormat:@"%ld", (long)indexPath.row]
<pre name="code" class="objc">didSelect方法获取单个点击/取消操作
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [collectionView deselectItemAtIndexPath:indexPath animated:YES]; NewShowCollectionViewCell *cell = (NewShowCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath]; dic_material = [_contacts objectAtIndex:[indexPath row]]; if ([[dic_material objectForKey:keyForChecked] isEqualToString:@"NO"] ) {// && [_editState isEqualToString:@"on"] [dic_material setObject:@"YES" forKey:keyForChecked]; [cell setChecked:YES]; id addObject = [_reouseArray objectAtIndex:[indexPath row]]; [self.removeList addObject:addObject]; }else{ [dic_material setObject:@"NO" forKey:keyForChecked]; [cell setChecked:NO]; id removeObject = [_reouseArray objectAtIndex:[indexPath row]]; [self.removeList removeObject:removeObject]; } }
// 全选操作- (void)editAllTheDeleteItems { if (is_editAll) { for (int i = 0; i < self.reouseArray.count; i ++) { NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0]; NewShowCollectionViewCell *cell = (NewShowCollectionViewCell*)[self.collectionView cellForItemAtIndexPath:indexPath]; NSUInteger row = [indexPath row]; NSMutableDictionary *dictionary = [_contacts objectAtIndex:row]; [dictionary setObject:@"YES" forKey:keyForChecked]; [cell setChecked:YES]; [self.removeList addObject:_reouseArray[i]]; is_editAll = NO; [_editAllBtn setImage:[UIImage imageNamed:@"全选2"] forState:(UIControlStateNormal)]; } }else{ for (int i = 0; i < self.reouseArray.count; i ++) { NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0]; NewShowCollectionViewCell *cell = (NewShowCollectionViewCell*)[self.collectionView cellForItemAtIndexPath:indexPath]; NSUInteger row = [indexPath row]; NSMutableDictionary *dictionary = [_contacts objectAtIndex:row]; [dictionary setObject:@"NO" forKey:keyForChecked]; [cell setChecked:NO]; [self.removeList removeObject:_reouseArray[i]]; is_editAll = YES; [_editAllBtn setImage:[UIImage imageNamed:@"全选1"] forState:(UIControlStateNormal)]; } }}
自定义cell中
<pre name="code" class="objc">- (void)setChecked:(BOOL)checked{ if (checked) { [_selectBtn setImage:[UIImage imageNamed:@"选择2"] forState:(UIControlStateNormal)]; } else { [_selectBtn setImage:[UIImage imageNamed:@"选择1"] forState:(UIControlStateNormal)]; } _checkedForSelect = checked;}
2 0
- iOS tableView编辑删除(单选 多选)
- ios tableview单选
- iOS-TableView编辑(多行编辑)
- iOS中tableview 中编辑,删除与多选中的问题(一)
- iOS疯狂详解之tableview编辑添加删除
- IOS-tableview编辑
- ios TableView那些事(三十 四)TableView 单选操作
- TableView中的编辑删除功能
- IOS开发之tableview单选
- 关于tableView多选删除的编辑设置
- iOS TableView多选删除理解2
- iOS tableView 如何禁止滑动手势删除,只允许在编辑模式下进行删除Cell
- ios tableview 插入删除
- ios tableView删除行
- iOS tableview 滑动删除
- iOS tableview 滑动删除
- ios tableview 删除按钮
- UITableView的编辑操作(移动&添加&删除-单选删除,或多选删除)
- c++ const修饰函数体,修饰返回值,修饰参数,和底层顶层指针的区别的简易
- 聚类算法实践(一)——层次聚类、K-means聚类
- Trap命令使用说明
- NSNotification、delegate和KVO的区别
- 关于架构优化和设计,架构师必须知道的事情
- iOS tableView编辑删除(单选 多选)
- laravel问题1
- 前端试题
- 递归类继承错误
- 关于android studio使用Google map报错的整理
- Oracle Dump 分析学习总结
- activity 左右侧滑跳转动画
- resin linux启动脚本
- 本页不但包含安全的内容,也包含不安全的内容