//删除好友
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete;
}
//先设置可以编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//进入编辑模式 按下出现编辑按钮
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView setEditing:NO animated:YES];
FriendsListModel *model = _contentSourceM[indexPath.section][indexPath.row];
_DeleteID = model.ID;
NSLog(@"%@",_DeleteID);
if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"你确定删除此好友" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alert show];
}
}
// alertView 监听 两种选择
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSLog(@"取消删除");
}else{
NSUserDefaults *publicSign = [NSUserDefaults standardUserDefaults];
NSString *signnn = [publicSign objectForKey:@"privateSign"];
NSDictionary *dict = @{
@"fid":_DeleteID,
@"sign":signnn
};
[ZSNetWorkRequest POST:DelFriend params:dict success:^(NSURLSessionDataTask *task, id responseObject) {
NSLog(@"删除成功");
[self requestData];
} fail:^(NSURLSessionDataTask *task, NSError *error) {
}];
}
}
//修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删勒个除";
}
//设置进入编辑状态时,Cell不会缩进
- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}