2010-06-26 2 views
28

UITableView 애니메이션 문제를 해결할 수있는 사람이 있습니까?UITableView add cell 애니메이션

기본적으로 UITableView에는 셀 및 재정렬 셀을 삭제하는 애니메이션이 있습니다.

우리는 애니메이션 추가 셀을 사용할 수 있습니까?

가 나는 테이블 MyProfile의> 리트 윗에서 애니메이션을 확장 할 어떻게 twitter하지 않았다 Three20을 체크 아웃했다.

Three20 frameowrk,UITableView의 기존 애니메이션을 사용하지 않고 사용해 보시기 바랍니다.

[self.dataSource addObject:@"New Item"]; 
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:[self.dataSource count]-1 inSection:0]; 
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; 

참고 : 데이터 소스 수에서 1 뺀 self.dataSource가 변경 가능한 배열되는 및 테이블 만 1 개 섹션을 갖는

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 

예 :

답변

60

다음과 같은 jQuery과 방법을 사용할 수 있습니다 NSIndexPath는 인덱스가 0이므로. 테이블 뷰

var myArray = ["Cow", "Camel", "Sheep", "Goat"] 

다음 테이블보기 상단에 애니메이션 행을 추가 할 데이터 소스이다

+0

코드를 보내 주셔서 감사합니다. 작동 샘플을 보내 주시겠습니까? o 삽입하는 동안 데이터 소스를 업데이트하는 방법과 약간 혼동 스럽습니다. – Ameya

+0

이전에 나는 데이터 소스 (NSMutableArray)에 레코드를 추가하고 [self.tableView reloadData]를 호출하는 것입니다; 하지만 그건 새로운 요소를 생생하게 가져 오지 않을 것입니다. – Ameya

+1

ur 코드의 작은 변화 @JK plz 답을 편집하여이 종류의 솔루션을 찾는 데 도움이되기를 바랍니다. [tableView insertRowsAtIndexPaths : [NSArray arrayWithObjects : [NSIndexPath indexPathForRow : [self.데이터 소스 개수] inSection : 0], nil] withRowAnimation : UITableViewRowAnimationRight]; – Ameya

10

스위프트

예 어레이.

// add item to current array 
myArray.insert("Horse", atIndex: 0) 

// insert row in table 
let indexPath = NSIndexPath(forRow: 0, inSection: 0) 
tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade) 

여러 업데이트

당신이 다음 다중 삽입 및/또는 삭제를 할 beginUpdates()endUpdates() 그들을 둘러싸고해야하는 경우.

tableView.beginUpdates() 
tableView.insertRowsAtIndexPaths([addIndexPath1, addIndexPath2, ...], withRowAnimation: .Fade) 
tableView.deleteRowsAtIndexPaths([deleteIndexPath1, deleteIndexPath2, ...], withRowAnimation: .Fade) 
tableView.endUpdates() 

추가 읽기

+1

내가 삽입해야하는 행을 삽입하려면 귀하의 코드를 사용하고 있지만 어떤 애니메이션 유형 내가 상관없이 항상 같은 방식으로 (즉, 페이드, botom, 왼쪽, 모든 행동을 애니메이션) . 이것이 일어나는 이유는 무엇입니까? –

+0

@GeorgeAvgoustis, 나는 잠시 동안이 일을하지 않았으므로 모르겠습니다. 나는 그것을 체크 아웃 할 것들에 대한 나의 목록에 올려 놓을 것이지만, 나는 잠시 동안 그것에 도달하지 않을 것이다. 먼저 알아 내면 다른 의견을 남겨주세요. – Suragch

0

사용 reloadRowsAtIndexPaths : indexPath

난이 당신을 도울 것입니다 희망
tableView.beginUpdates() 
    [tableView reloadRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationAutomatic]; 
    tableView.endUpdates() 

..