-(void)editAction:(UIButton*)sender
{
[self.tableView setEditing:YES animated:YES];
sender.selected=!sender.selected;
NSLog(@"%d",sender.selected);
[sender setTitle:sender.selected?@"完成":@"编辑" forState:UIControlStateNormal];
[_tableView reloadData];
if (sender.selected)
{
self.tableView.editing=YES;
if (self.tableView.editing==YES) {
}
[self addAllSelectView];
}
if (!sender.selected) {
self.tableView.editing=NO;
self.tableView.frame = CGRectMake(0, 0, iPhoneWidth, iPhoneHeigt);
self.editView.hidden = YES;
}
}
// 设置tableView是否可以删除
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
// 设置删除操作时候的标题
-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return @"删除";
}
//问题2:某一行支持哪种编辑模式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;//|UITableViewCellEditingStyleInsert;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"%ld",(long)editingStyle);
if (editingStyle==UITableViewCellEditingStyleDelete)
{
[SVProgressHUD show];
if (self.DeleteCollectionBlock)
{
self.DeleteCollectionBlock();
}
NSString *codeString=[NSString stringWithFormat:@"%@-%@",UserID,KEY];//(md5(account-key))
NSString *code=[NSString md5:codeString];
// MD5加密
NSString *urlString=[NSString stringWithFormat:、xxxxxxxxxxxxxxxxxxx];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"user_id"] = UserID;
params[@"act"] = @"delete";
params[@"rec_id"] = [dataArray[indexPath.row] objectForKey:@"rec_id"];
[[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
NSLog(@"%@",urlString);
[WXNetworking WXBaseNetworkWithPOST:xxxxxx params:params success:^(id responseObject) {
// 删除成功后移除数据源并刷新tableView
[dataArray removeObjectAtIndex:indexPath.row];
[tableView endUpdates];
[tableView reloadData];
} failure:^(NSError *error) {
}];
}
if (editingStyle == UITableViewCellEditingStyleInsert) {
NSIndexPath *newIP=[NSIndexPath indexPathForItem:dataArray.count-1 inSection:0];
[tableView insertRowsAtIndexPaths:@[newIP] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
for (UIView *view in cell.subviews) {
if ([view isKindOfClass:NSClassFromString(@"UITableViewCellEditControl")])
{
for (UIView *vVV in view.subviews) {
NSLog(@"%@",vVV);
[vVV removeFromSuperview];
}
WXButton* checkButton= [self checkBox:CGRectMakeE(0,0,47,110)];
NSLog(@"%ld",(long)indexPath.row);
NSInteger row=indexPath.row;
int ii=(int)row;
NSLog(@"%d",ii);
checkButton.hang=ii;
[checkButton addTarget:self action:@selector(checkButton:) forControlEvents:UIControlEventTouchUpInside];
for (NSDictionary *temDict1 in _selectArray)
{
if (dataArray[indexPath.row] == temDict1) {
checkButton.selected = YES;
}else{
}
}
[view addSubview:checkButton];
}
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
cell.preservesSuperviewLayoutMargins = NO;
}
// 多选时选中取消的操作
// 自定义的选中按钮 对选中按钮的勾选做对删除分组的操作
-(void)checkButton:(WXButton*)sender{
sender.selected=!sender.selected;
if (sender.selected==YES)
{
model = self.modelArray[sender.hang];
model.isSelect = YES;
[_selectArray addObject:dataArray[sender.hang]];
}
if (sender.selected == NO)
{
//遍历删除数组 对所勾选的商品做出操作 _selectArray是要删除tableViewcell的数组 遍历对比选中的数组 tempArray 的使用是因为一个数组不能同事在两个线程做操作。
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:_selectArray];
for (NSDictionary *tempDic in _selectArray)
{
if (tempDic == dataArray[sender.hang])
{
[tempArray removeObject:tempDic];
}
_selectArray = tempArray;
}
}
}