2012-01-07 2 views
-3

을 ... 스크롤 한 후 행을 반복사용자 지정 UITableViewCells 내가 해결책을 찾고 있어요

코드 : I 셀에 문제가 반복하여, 문제가 될 때 발생하는 경향이 있음을 발견

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSString *CellIdentifier = @"ItemCardapio"; 
    NSString *nibName = @"ItemCardapioCell"; 

    ItemCardapioCell *cell = (ItemCardapioCell *) [self.restaurantsList dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil]; 
     cell = (ItemCardapioCell *)[nib objectAtIndex:0]; 

     [cell initCellWithRestaurant:@"" tipoRestaurante:@""];  
    } 

    return cell; 
} 
+4

1. 무엇을위한 솔루션을 찾고 있나요? 2. 코드에 의미있는 설명을 추가하십시오! 3. 코드를 포맷하십시오! – Krizz

답변

5

너는 if (cell == nil) 비트에 넣으면 안되는 것들을 넣는다.

이유는 적절한 셀 부분을 적절히 업데이트하지 않으면 잘못된 재사용 셀을 사용하여 테이블보기가 종료되기 때문입니다.

직접적으로 if (cell == nil) 비트에서 셀을 변경하는 모든 것을 가져오고 반복되는 셀에 문제가 없어야합니다.

+0

bravo 남자의 황금 팁 –

0

Heres는 내가 정의 세포에 사용하는 것을 :

static NSString *cellIdentifier = @"ItemCardapioCell"; 

    ItemCardapioCell *cell = (ItemCardapioCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if (cell == nil) { 

     NSLog(@"Creating Cell"); 

     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ItemCardapioCell" owner:nil options:nil]; 

     for(id currentObject in topLevelObjects) 
     { 
      if([currentObject isKindOfClass:[ItemCardapioCell class]]) 
      { 
       cell = (ItemCardapioCell *)currentObject; 
       break; 
      } 
     } 
    }; 
+0

작동하지 않는다 : (일부 서브 뷰를로드하는 셀에 하나의 UIScrollview가 있습니다.이 셀은 3 행마다 반복됩니다. 내 나쁜 영어를 죄송합니다. –

+0

UITableViewCell에 UIScrollview가 있습니다 어떻게 구현 (추가) 셀에 UIScrollView? 나는 그것에 대해 아무것도 볼 수 없습니다. 내가 쓴 코드는 사용자 지정 셀을 모든 행에 대해 tableview로드 된 얻을 수 있습니다. –

+0

UIScrollView 일부 하위 뷰를로드하는 ItemCardapioCell 내부. 내 생각은 모든 행을 가로 탐색, 있지만 일부 행을 반복합니다. –

관련 문제