2011-04-06 3 views

답변

112
[self.tableView beginUpdates]; 
[self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade]; 
[self.tableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationFade]; 
[self.tableView endUpdates]; 

insertIndexPaths은 테이블에 삽입 할 NSIndexPaths의 배열입니다.

deleteIndexPaths은 테이블에서 삭제할 NSIndexPaths의 배열입니다. 인덱스 경로에 대한

예 배열 형식 :

NSArray *insertIndexPaths = [[NSArray alloc] initWithObjects: 
     [NSIndexPath indexPathForRow:0 inSection:0], 
     [NSIndexPath indexPathForRow:1 inSection:0], 
     [NSIndexPath indexPathForRow:2 inSection:0], 
     nil]; 
+0

답변 해 주셔서 감사합니다! 당신의 방법을 다음과 같이 사용했습니다 :'\t \t NSArray * insertIndexPaths = [[NSArray alloc] initWithObjects : [NSIndexPath indexPathForRow : 0 inSection : 0], nil]; \t \t \t \t [theTableView beginUpdates]; \t \t [theTableView deleteRowsAtIndexPaths : insertIndexPaths withRowAnimation : UITableViewRowAnimationLeft]; \t \t [theTableView endUpdates]; '하지만 여전히 아무것도하지 못했습니다. 'theTableView' 부분과 관련이 있다고 생각합니다. 'self.tableView'를 시도 할 때 구조체 또는 합집합이 아니라고 알려줍니다 ... 감사합니다! – iosfreak

+0

당신의 뷰 컨트롤러는 UITableViewController를 서브 클래스화할 필요가 있거나 UIViewController 일 경우 UITableViewDelegate와 UITableViewDataSource 프로토콜을 함축적으로 구현해야합니다. 그런 다음 인터페이스 빌더에서 뷰에 테이블 뷰를 추가하고 뷰 컨트롤러에 delegate 및 dataSource 속성을 연결합니다. – Sabobin

+0

UITableViewDelegate 및 DataSource (내보기에서 내 UITableView에 연결되어 있습니다) UIViewController 같이 내 하위 클래스가 있습니다. 내가 뭘 잘못하고 있니? – iosfreak

4

insertRowsAtIndexPaths:withRowAnimation:deleteSections:withRowAnimation: 두 가지 방법을 사용하려면 UITableView documentation에 모두 입력해야합니다.

+0

감사합니다. 여기 내가하고있는 일이있다 :'\t \t \t [processList removeObjectAtIndex : 0]; \t \t \t [theTableView beginUpdates]; \t \t \t [theTableView deleteRowsAtIndexPaths : 0 withRowAnimation : UITableViewRowAnimationFade]; \t \t \t [theTableView deleteSections : 0 withRowAnimation : UITableViewRowAnimationFade]; \t \t \t [theTableView endUpdates]; 그러나 아무 반응이 없습니다. – iosfreak

7

tableView.beginUpdates() 
tableView.deleteRowsAtIndexPaths([YourIndexPathYouWantToDeleteFrom], withRowAnimation: .Fade) 
tableView.insertRowsAtIndexPaths([YourIndexPathYouWantToInsertTo], withRowAnimation: .Fade) 
tableView.endUpdates() 

스위프트 2.1

에서 그리고 당신과 같이 쉽게 NSIndexPath를 만들 수 있습니다 답장을

NSIndexPath(forRow: 0, inSection: 0) 
관련 문제