2011-07-06 3 views
1

스크롤하는 동안 UITableViewCell이 할당 된 경우 다시 할당하면 안됩니다. 그러나 그것은 그렇습니다. 어떻게 그 일이 일어나지 않도록 할 수 있습니까?스크롤 할 때 UITableViewCell이 반복적으로 할당 됨

+0

조건 경우이 외부의 원하는 것을 제어 할 경우 당신은 정확히 우리가 아이디어를 얻을 수 있도록 최선을 다하고 있습니다 ... – iBapu

답변

0

무엇에 대한 몇 가지 코드를 작성하는 당신이이 레이블을 cellForRowAtIndexPath 코드를 그

static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 


    if (cell == nil) 
    { 
    CGRect CellFrame; 

     CGRect nameLabelFrame; 

     CGRect countLabelFrame; 

     CellFrame = CGRectMake(0, 0, 320, 80); 

     nameLabelFrame = CGRectMake(10, 10, 270, 50); 
     countLabelFrame = CGRectMake(10, 58, 270, 12); 


     cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:CellIdentifier] autorelease]; 
     UILabel *lblTemp; 
     //UIImageView *imgTemp; 

     lblTemp = [[UILabel alloc] initWithFrame:nameLabelFrame]; 
     lblTemp.tag = 1; 
     [cell.contentView addSubview:lblTemp]; 
     [lblTemp release]; 



     lblTemp = [[UILabel alloc] initWithFrame:countLabelFrame]; 
     lblTemp.tag = 3; 
     [cell.contentView addSubview:lblTemp]; 
     [lblTemp release]; 

} 

//And outside of if condition access these labels by this 

    //UIConstruction 
     UILabel *nameLabel = (UILabel *)[cell viewWithTag:1]; 

     UILabel *countLabel = (UILabel *)[cell viewWithTag:3]; 

같은 몇 가지 일을 셀을 재사용하고 사용하고자하거나

+0

이것이 왜 downvoted ??? – KingofBliss

+0

'initWithFrame : reuseIdentifier'는 3.0처럼 사용되지 않으며, 이제 delegate 메소드로 height가 설정됩니다. 또한 태그를 사용하는 대신 UITableViewCell을 서브 클래스 화하고 UILabels을 해당 클래스의 속성으로 설정하는 것이 좋습니다. 특별히'setFrame : '을 재정 의하여 셀의 크기가 조정될 때 크기를 조정할 수 있으므로 – EmilioPelaez

+0

@EmilioPelaez 프레임을 설정함으로써 그렇다고 heightForRowAtIndexPath를 사용하지 않을 수도 있습니다. 이것은 프레임을 조정하기위한 것입니다. 또한 정확한 해결책을 제공하지 않습니다. 전체 코드를 작성할 사람은 아무도 없습니다. 셀 재사용을위한 또 다른 방법이 있습니다. 솔루션은 셀을 다시 사용합니다. – Ishu

관련 문제