2012-11-08 2 views
0

데이터 목록을 표시하는 UITableView이 있습니다.iPhone - UITableView에 새 섹션 및 행 추가

목록에 이미지가 포함되므로 이미지를로드하는 데 지연 시간이 걸립니다. 이제는 한 번에 전체 목록을로드하고 싶지 않습니다.

로딩은 먼저 10 개의 레코드를로드해야하며 tableview으로 스크롤하면 다음 10 개의 레코드가 자동으로로드됩니다.

이렇게하려면 아래로 스크롤 할 때 행을 추가해야합니다. tableview에는 다른 섹션이 포함될 수 있습니다.

스크롤하는 동안 tableview 끝에 새 행과 새 섹션을 추가하려면 어떻게합니까?

답변

1

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    if (indexPath.row == [yourArray count]-1) 
     { 
     //start fetching the next set of data in background asynchronously and when fetching is complete use delegate methods to reload or append your current UITableView , meanwhile start a activity indicator as footer to show loading 
     } 
    } 

당신이 스크롤이 바닥에 도달 할 때 동 기적으로 실행하려고하면이, 효과적인 방법에서, 그것은 당신의 장치가 Apple documentation about UITableView에서

1

봐 붙어 만들 것입니다. 당신은 행 추가 다음과 같은 방법을 사용할 수 있습니다 :

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

첫째, 당신이해야 할 일이 게으른로드로 알려져있다.

귀하의 테이블보기는 이미지를로드하거나 현재 사용자에게 표시되는 셀에 데이터를 표시합니다. 그래서 this 링크를보십시오. 그것은 당신을 도울 수있는 샘플 코드를 제공합니다.

그리고 행을 삽입, 당신은 사용할 수 있습니다

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