當我的UITableView頂部和底部單元格每當他們滾動和返回到屏幕上時,我都遇到了問題。我認爲這是重複使用標識符的問題,但我不確定如何解決此問題。 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;
}
編輯:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.placesArray count];
}
從我ABTableViewCell的子類:
- (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