iOS,UITableView 왼쪽 슬라이딩 삭제 복사 기능 구현

개발 프로젝트 를 할 때 tableview 왼쪽 미끄럼 으로 삭제 해 야 한 다 는 것 을 연구 해 보 았 습 니 다.더 이상 말 하지 않 고 코드 를 직접 올 렸 습 니 다.

// Cell   
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
  return YES;
}
//      
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
  return UITableViewCellEditingStyleDelete;
}
//    (  )  
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{  
  //  alterView      
  [tableView setEditing:NO animated:YES];
  if (editingStyle == UITableViewCellEditingStyleDelete) {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"  " message:@"        ?" preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"  " style:UIAlertActionStyleCancel handler:nil]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"  " style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
      //             ,          
      [reconnaissanceListArr removeObjectAtIndex:indexPath.row];
      [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
  }
}
//        
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
  return @"  ";
}
//         ,Cell    
- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
  return NO;
}
총결산
위 에서 말 한 것 은 편집장 님 께 서 소개 해 주신 iOS 가 UITableView 왼쪽 슬라이드 를 통 해 복사 기능 을 삭제 하고 사용 하 는 것 입 니 다.도움 이 되 셨 으 면 좋 겠 습 니 다.궁금 한 점 이 있 으 시 면 메 시 지 를 남 겨 주세요.편집장 님 께 서 바로 답 해 드 리 겠 습 니 다.여기 서도 저희 사이트 에 대한 여러분 의 지지 에 감 사 드 립 니 다!

좋은 웹페이지 즐겨찾기