//删除
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath
{
NSString *strurl =[NSStringstringWithFormat:@"%@/menus.php",HTTP_SERVER];
NSURL *url = [NSURL URLWithString:strurl];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSMutableDictionary *postDic = [[NSMutableDictionary alloc] init];
//getUserList 请求数据
[postDic setObject:@"deleteMenu" forKey:@"action"];
NSString *str=[self.tableDic allKeys][indexPath.section];
NSMutableArray *ary=[self.tableDic objectForKey:str];
[postDic setObject:[[ary objectAtIndex:indexPath.row]objectForKey:@"MID"] forKey:@"MID"];
NSData *postData = [NSJSONSerialization dataWithJSONObject:postDicoptions:NSJSONWritingPrettyPrinted error:nil]; //data是字符串
NSString *postString = [[NSString alloc] initWithData:postDataencoding:NSUTF8StringEncoding];
[request setPostValue:postString forKey:@"data"]; //传值
[request setCompletionBlock:^{
//阻塞块可以吧整个函数作为变量,传到setCompletionBlock中
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[ary removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationFade];
}
}]; //返回数据
[request setFailedBlock:^{
}];
[request startAsynchronous];
[postString release];
//[_tableView reloadData];
}