2011-08-12 5 views
22

나는 UITableView을 가지고 있습니다. 선택에 따라 테이블 데이터를 업데이트하고 싶습니다. 지금은 [mytable reloadData]을 사용합니다. 선택한 특정 셀을 업데이트 할 수있는 방법이 있는지 알고 싶습니다. NSIndexPath 등을 사용하여 수정할 수 있습니까? 어떤 제안?iOS의 Reload specific UITableView 셀

감사합니다.

답변

62

, 당신은 그냥 전화를해야 :

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation; 

섹션 2의 3 행을 다시로드하고, 예를 들어 섹션 3의 4 행을 실행하려면 다음을 수행해야합니다.

// Build the two index paths 
NSIndexPath* indexPath1 = [NSIndexPath indexPathForRow:3 inSection:2]; 
NSIndexPath* indexPath2 = [NSIndexPath indexPathForRow:4 inSection:3]; 
// Add them in an index path array 
NSArray* indexArray = [NSArray arrayWithObjects:indexPath1, indexPath2, nil]; 
// Launch reload for the two index path 
[self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade]; 
+0

색인 경로에 익숙하지 않습니다. 좀 자세히 설명해 주실 수 있습니까? – pa12

+1

NSIndexPath는 이름이 인덱스를 보유하고 있음을 나타냅니다. 색인은 2 개의 구성 요소 행과 섹션으로 구성됩니다. [NSIndexPath indexPathForRow : (NSUInteger) inSection : (NSUInteger)]를 사용하여 하나를 만들 수 있습니다. – Abhinit

+0

각 섹션은 여러 행을 가질 수 있습니다. 예를 들어 iPod MP3 플레이어에는 각 문자에 대한 섹션이 있습니다. 이 섹션에는 각각 여러 아티스트가 포함되어 있습니다. 원본 코드를 편집하여 수행 방법을 보여줍니다. – CedricSoubrie

2

난 당신이 UITableView이 방법을 찾고 있다고 생각 : 위의 아이폰 OS 3.0에 대한

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 
6

UITableViewCell 객체를 수정하고 라벨 등을 변경하십시오.

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath]; 
cell.textLabel.text = @"Hey, I've changed!";