2010-04-22 2 views
0

인터페이스 빌더에서 만든 사용자 정의 UITableViewCell이 있습니다. 나는 성공적으로 셀을 dequeuing하고 있지만 스크롤 할 때 셀은 다른 indexPath를 호출하기 시작하는 것처럼 보입니다. 이 예제에서는 현재 indexPath.section 및 indexPath.row를 customCellLabel에 제공하고 있습니다. 테이블을 위아래로 스크롤하면 일부 셀이 바뀝니다. 숫자는 모든 곳에있을 수 있지만 셀은 시각적으로 건너 뛰지 않습니다.스크롤하는 동안 사용자 정의 UITableViewCell이 indexPath를 변경합니까?

if (cell == nil)을 주석 처리하면 문제가 사라집니다.

표준 셀을 사용하면 문제가 해결됩니다.

왜 이런 일이 벌어지고 있을지 생각해보십시오.

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CalendarEventCell"]; 
    if (cell == nil) { 
     NSLog(@"Creating New Cell !!!!!"); 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CalendarEventCell" owner:self options:nil]; 
     cell = (UITableViewCell *)[nib objectAtIndex:0]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 


    // Set up the cell... 
    [customCellLabel setText:[NSString stringWithFormat:@"%d - %d",indexPath.section, indexPath.row]]; 


    return cell; 
} 
+0

customCellLabel이란 무엇입니까? – jamesmoschou

+0

customCellLabel은 Interface Builder에서 만든 CalendarEventCell에 포함 된 레이블입니다. – Chris

답변

2

당신이 (셀 == 전무) 조건, 당신은 "CalendarEventCell"로 셀에 reuseIdentifier를 할당하는 경우의 셀을 만들? 나는 당신의 펜촉 이름 CalendarEventCell입니다 볼 수 있습니다,하지만 난 당신이 또한 그때가 올바른 세포를 양단 할 수 있는지 확실하지 않다,

cell.reuseIdentifier = @"CalendarEventCell";

그렇지 않으면 설정해야 할 것 같아요. 또한 customCellLabel이 무엇을 참조하는지 잘 모릅니다.

+0

펜촉을 사용하여 재사용 가능한 셀을 만들 때 Interface Builder에서 reuseIdentifier를 설정합니다. 재사용 식별자를 파일 이름과 동일하게 설정했습니다. 테이블을로드 할 때 NSLogs 몇 개를 얻었 기 때문에 올바르게 셀을 큐에서 제거한다고 생각합니다. 위와 아래로 스크롤 할 때 NSLog가 추가로 필요하지 않습니다. – Chris

+0

또한 cell.resuseIdentifier를 그런 식으로 설정할 수 없습니다. reuseIdentifier는 읽기 전용입니다. – Chris

+0

죄송합니다. 나는 그 중 하나를 놓쳤습니다. 당신 말이 맞아요. 읽기 전용 속성이며 재사용 할 셀을 만들 때만 설정할 수 있습니다. –