2013-09-29 7 views
-1

이전 질문과 중복 될 수 있지만 내 기록이 왜 복제되는지 알 수 없습니다. 테이블이 행을 재활용하려고 시도한다는 것을 알고 있습니다. 테이블이 테이블에 삽입 된 모든 데이터 조각에 대해 더 많은 셀을 추가하는 것처럼 보입니다.UITableView에서 중복 됨

예를 들어 2 레코드의 경우 4 행을 얻습니다. 3 레코드의 경우 9 행을 얻습니다. 여기

코드 :

UITable 위임 물건 :

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    return nil; 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return letters.count; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return letters.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    printf("%li", (long)indexPath.row); 

    [cell textLabel].text = [letters objectAtIndex:indexPath.row]; 

    return cell; 
} 

나는 데이터가 이미 먼저 표시되었는지 확인해야합니까?

답변

1

답을 찾았습니다. 매우 어리석지 만 놓치기 쉽습니다. 다음과 같이 설정했습니다 :

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return letters.count; 
} 

은 표시 할 섹션이 1 개이므로 1로 설정해야합니다. 누군가가 똑같은 어리석은 실수를 저지른다면 나는 여기에 남겨 둘 것입니다!

IE

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
}