2011-12-01 2 views
0

UITableView 위쪽과 아래쪽 셀이 화면을 벗어나 스크롤 할 때마다 번갈아 표시되는데 문제가 있습니다. 나는 이것이 reuseIdentifier에 관한 문제라고 생각하지만, 나는 그걸 해결하는 방법을 모르겠습니다. PlaceTableViewCell은 빠른 스크롤을위한 Loren Britcher의 ABTableViewCell의 하위 클래스입니다.UITableView reuseIdentifier : 위쪽과 아래쪽에있는 요소를 반복합니다.

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

    static NSString *uniqueIdentifier = @"Cell"; 

    PlaceTableViewCell *cell = (PlaceTableViewCell *)[tableView dequeueReusableCellWithIdentifier:uniqueIdentifier]; 


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

    Places *place = [self.placesArray objectAtIndex:[indexPath row]];  
    cell.place_title = place.title; 
    cell.place_street = place.street; 
    cell.place_thumb = place.thumb_path; 


    return cell; 

} 

편집 : ABTableViewCell의 내 서브 클래스에서

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [self.placesArray count]; 
} 

:

- (void)drawContentView:(CGRect)r 
{ 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    UIColor *backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]; 
    UIColor *textColor = [UIColor blackColor]; 

    if(self.selected) 
    { 
     backgroundColor = [UIColor clearColor]; 
     textColor = [UIColor whiteColor]; 
    } 

    [backgroundColor set]; 
    CGContextFillRect(context, r); 

    CGPoint p; 
    p.x = 42; 
    p.y = 2; 

     NSLog(@"place_thumb: %@", place_thumb); 

     NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:place_thumb]]; 
     UIImage *image = [UIImage imageWithData:imageData]; 
     [image drawAtPoint: p]; 


     p.x = p.x + 50; 

     [textColor set]; 
     [place_title drawAtPoint:p withFont:place_titleFont]; 

     p.y = 25; 

     textColor = [UIColor lightGrayColor]; 
     [textColor set]; 
    [place_street drawAtPoint:p withFont:place_streetFont]; 

} 
+0

문제는 무엇입니까? – john

+0

아래로 스크롤하여 맨 위로 스크롤하면 마지막 요소가 첫 번째 요소 대신 사용됩니다. 위아래로 스크롤하면 그 반대가 발생합니다 (첫 번째 요소가 마지막이됩니다) –

+0

모두 같은 섹션에 있습니까? – john

답변

0

당신의 cellForRowAtIndexPath가 올 것으로 보인다. UITableView에 대한 모든 데이터 소스 메소드를 게시해야합니다. numberOfRows 메소드에서 문제가 발생했을 가능성이 있습니다.

배열 크기에 따라 행 수를 설정하고 있습니까? 또한 배열이 변경되지 않았습니까?

+0

배열이 변경되지 않은 상태로 유지됩니다 ... 또한 drawContentView를 게시했습니다. 저도 같은 스레드에서 dataWithContentsOfURL와 이미지 로딩은 그렇게 발생할 것 지연의 원인이 될 수 ... 문제의 원인이 될 수 있습니다 의심? –

+0

사실 나는 원격 이미지 대신 정적 이미지를로드하려고 시도했으나 문제는 지속되었습니다 ... –

+0

흠 이것은 매우 혼란 스럽습니다. 각 셀마다 다른 식별자를 설정하면 어떻게됩니까? 실험을 위해서 indexPath.row를 cellIdentifier로 사용하십시오. 중복이 여전히 발생하면 문제가되는 테이블 뷰의 데이터 소스 메소드를 제외 할 수 있습니다. – Sid

관련 문제