삭제 버튼을 표시하지 않고 테이블보기 셀에서 왼쪽 또는 오른쪽으로 스 와이프하여 애니메이션이있는 셀을 지우고 싶습니다. 어떻게해야합니까?UITableViewCell에서 아무 곳이나 왼쪽 또는 오른쪽으로 스 와이프하여 삭제 버튼이없는 셀을 삭제 하시겠습니까?
답변
저는 이것을 시도하지는 않았지만 구현해 보았습니다. 첫째, 사용자 지정있는 UITableViewCell을 만들고, 당신이 그것에서 사용하고있는있는 tableView에
- 에 대한 참조를 사용할 수있는 2 곳을 보자.
- indexPath을있는 tableView의 셀을 찾을 수 있습니다. (참고, 이 변경되는 모든 셀의 셀을 삭제할 때마다 업데이트해야합니다.)
cellForRowAtIndexPath:
에서 사용자 지정 셀을 만드는 위치에서 이러한 속성을 설정합니다. 또한 셀에 UISwipeGestureRecognizer를 추가하십시오.
cell.tableView=tableView;
cell.indexPath=indexPath;
UISwipeGestureRecognizer *swipeGestureRecognizer=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(deleteCell:)];
[cell addGestureRecognizer:swipeGestureRecognizer];
[swipeGestureRecognizer release];
제스처는 수평 스 와이프 만 수신해야합니다. @MadhavanRP에 의해 게시하여 deleteCell:
-(void) deleteCell:(UIGestureRecognizer*)gestureRec
{
UIGestureRecognizer *swipeGestureRecognizer=(UISwipeGestureRecognizer*)gestureRec;
CustomCell *cell=[swipeGestureRecognizer view];
UITableView *tableView=cell.tableView;
NSIndexPath *indexPath=cell.indexPath;
//you can now use these two to perform delete operation
}
제스처 인식기의 방향을 처음 초기화 할 때 방향을 설정하여 셀에 추가해야한다는 점을 잊지 마십시오. 이런 식으로 : swipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight; – ColossalChris
애플,'(void) cancelPreviousPerformRequestsWithTarget : (id) aTarget selector : (SEL) aSelector'를 제공하지 않으 셨습니다. –
귀하의 프로젝트에이 코드를 추가해야합니다.
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}
그렇지 MOR 정보 유 enter link description here
Vivek2012 및 iWill - 답장을 보내 주셔서 감사합니다. 그러나 DELETE 버튼을 표시하고 싶지는 않습니다. 이미 stackoverflow에있는 답변이 있습니다. 슬쩍 왼쪽 또는 오른쪽 제스처를받는 순간 셀을 지우고 싶습니다.내 설명을 읽어 주셔서 감사합니다 – carbonr
가
하여 셀을 삭제 STH를 UITableViewCellEditingStyle가 UITableViewCellEditingStyleDelete 인 경우,- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
이 두 가지 방법을 시행하고이 링크를 통해 이동할 수 있습니다
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
그게 전부입니다.
솔루션에서
는-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if([[gestureRecognizer view] isKindOfClass:[UITableViewCell class]]&&
((UISwipeGestureRecognizer*)gestureRecognizer.direction==UISwipeGestureRecognizerDirectionLeft
||(UISwipeGestureRecognizer*)gestureRecognizer.direction==UISwipeGestureRecognizerDirectionRight)) return YES;
}
작동하지만은 필요 이상으로 더 복잡하다. 보다 간단한 방법을 사용하여 테이블에서 발생하는 모든 스 와이프를 처리하는 제스처 인식기를 만든 다음 스 와이프 위치를 가져 와서 사용자가 스 와이프 한 셀을 확인할 수 있습니다. 설정하려면
제스처 인식기 :
- (void)setUpLeftSwipe {
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeLeft:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.tableView addGestureRecognizer:recognizer];
recognizer.delegate = self;
}
전화 슬쩍 처리 할 수 viewDidLoad
에서이 방법
- (void)swipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer {
CGPoint location = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
... do something with cell now that i have the indexpath, maybe save the world? ...
}
참고 : 당신의 VC는 제스처 인식기 대리자를 구현해야합니다 .
- 1. 왼쪽으로 스 와이프하여 삭제 및 편집, 삭제
- 2. Android 왼쪽 또는 오른쪽으로 스 와이프 하시겠습니까?
- 3. 삭제하려면 스 와이프하여 왼쪽에서 오른쪽으로 스 와이프가 작동하지 않음
- 4. "스 와이프하여 삭제"하지만 모든 셀에 적용되지 않습니다.
- 5. 스 와이프하여
- 6. UITableView가 "스 와이프하여 삭제"모드로 들어 가지 않습니다.
- 7. 삭제하려면 스 와이프하여 UITableViewCell을 왼쪽으로 이동하십시오.
- 8. iOS4 - 스 와이프하여 UIWebview URL을 변경 하시겠습니까?
- 9. 삭제 또는 가상 삭제 하시겠습니까?
- 10. android : 슬라이드보기에서 왼쪽 또는 오른쪽으로 스 와이프
- 11. 선택적 UITableView 셀을 삭제 하시겠습니까?
- 12. 오른쪽으로 스 와이프하여 밀어 넣은 Segue에 왼쪽으로 스 와이프
- 13. 왼쪽/오른쪽으로 스 와이프 이벤트
- 14. 테이블 셀을 스 와이프하여 두 가지 옵션을 얻을 수 있습니다.
- 15. 스 와이프하여 다른 plists로 전환 하시겠습니까?
- 16. UITableViewCell에서 삭제 버튼 추가/시뮬레이션
- 17. 아이폰 키보드 뒤에있는 셀을 삭제 하시겠습니까?
- 18. UITableViewCell의 삭제 액세서리보기 변경
- 19. 편집 모드에서 이미 스 와이프하여
- 20. 기본 애니메이션 (스 와이프하여 회전)
- 21. Android에서 한 번 스 와이프하여 갤러리보기를 다음 이미지로 이동 하시겠습니까?
- 22. 이미지를 왼쪽 또는 오른쪽으로 슬라이드
- 23. 레이아웃 또는 컨테이너에서 왼쪽 또는 오른쪽으로 플로팅 하시겠습니까?
- 24. TableView 스 와이프 - 삭제 기능이 작동하지 않습니다.
- 25. 아무 곳이나 플롯
- 26. 데이터베이스 : 가져 오기 및 삭제 또는 삭제 만 하시겠습니까?
- 27. Chrome로드 알림을 삭제 하시겠습니까?
- 28. 스 와이프하여 전환 탭 선택
- 29. 삭제 테이블 뷰 셀 (anoher 버튼을 삭제 작업을 용한) 왼쪽에있는 버튼을 삭제 빨간색 기본없이 왼쪽 테이블 뷰의 셀을 삭제하는 방법
- 30. 이상한 동작으로 셀을 삭제하려면 스 와이프
가능한 경우 코드를 게시 하시겠습니까? –