码迷,mamicode.com
首页 > 其他好文 > 详细

tableview侧滑删除

时间:2015-06-16 16:01:41      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return NO;
    }
    return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return @"删除";
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSInteger index = (indexPath.section-1);
        Address *address = [self.addressArray objectAtIndex:index];
        
        //联网删除地址
        [SVProgressHUD showWithStatus:@"正在删除.."];
        NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:address.AddressID, @"AddressID", nil];
        [self.afServiceHelper getDefaultJsonWithSubMethod:@"AddressInfo_AddressID_Delete" parameters:dict cachePolicy:NSURLRequestUseProtocolCachePolicy success:^(id json) {
            [SVProgressHUD dismiss];
            NSDictionary *resultDict = json;
            if ([[resultDict objectForKey:M_Code] integerValue] == 0) {
                [self.addressArray removeObjectAtIndex:index];
                NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:indexPath.section];
                [tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationLeft];
            } else {
                [self.tableView makeToast:[resultDict objectForKey:M_Msg] duration:1.0 position:@"center"];
            }
            
        } failure:^(NSError *error, NSString *msg) {
            if(error.code == NSURLErrorNotConnectedToInternet) {
                [SVProgressHUD dismiss];
                [self.tableView makeToast:@"没有网络" duration:1.0 position:@"center"];
            } else {
                [SVProgressHUD dismissWithError:@"删除失败"];
            }
        }];
        
    }
}

 

tableview侧滑删除

标签:

原文地址:http://www.cnblogs.com/apem/p/4580823.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!