iOS tableView编辑删除(单选 多选)
2016-05-18 10:02
447 查看
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; }
相关文章推荐
- iOS崩溃 捕获异常处理
- iOS 当前应用所占内存和设备可用内存
- iOS后台运行定时器
- iOS之如何自适应TableViewCell的高度
- 监听用户进入,离开某个区域,需要请求获取用户的位置,如果想在后台也能监听,需要配置ios9后台监听
- iOS 后台定位审核被拒How to clarify the purpose of its use in the location modal?
- iOS学习笔记36-Masonry自动布局
- iOS深复制和浅复制
- iOS深入学习(Block全面分析)
- iOS开发——响应链(Responder Chain)的深入理解和代码示例
- [置顶] iOS在沙盒Documents中创建文件夹以及获取沙盒路径
- ios 9.0获取用户位置
- 获取用户位置ios8.0以上适配
- ios 获取用户的位置
- iOS模块化之路(一)
- 【代码笔记】iOS-两个滚动条,上下都能滑动
- iOS中NSUserDefaults的用法(轻量级本地数据存储)
- iOS - block
- iOS开发之断点续传原理与实现
- iOS支付宝支付--密钥制作