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];
}
문제는 무엇입니까? – john
아래로 스크롤하여 맨 위로 스크롤하면 마지막 요소가 첫 번째 요소 대신 사용됩니다. 위아래로 스크롤하면 그 반대가 발생합니다 (첫 번째 요소가 마지막이됩니다) –
모두 같은 섹션에 있습니까? – john