基於Apple's TableViewSuite sample project我採用了5號結構,以創建自定義繪製表格單元格。這個工作很棒,和我使用筆尖時相比,滾動速度非常棒。iPhone UITableView單元變得「卡住」並與快速滾動混淆
但是它已經推出了一個錯誤,我想不通 - 如果我在屏幕上快速滾動左右,細胞內容物似乎弄混和細胞將展示其應該出現在另一個單元格的內容。有時多個單元甚至會顯示相同的內容。如果我點擊並按住單元格就好像選擇它一樣,它會再次刷新到正確的內容。我已經驗證了正確的單元格正在傳遞來自表的viewcontroller中的數組的正確數據,所以我猜這是一些圖形故障。
任何幫助將是偉大的,我不能解決我做了什麼不同樣品。以下相關代碼:
視圖控制器cellforrowatindexpath
static NSString *CellIdentifier = @"FacilityCell";
StoreDetailFacilityCell *cell = (StoreDetailFacilityCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[StoreDetailFacilityCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
[cell configureCell:[storeFacilities objectAtIndex:indexPath.row] atRow:indexPath];
return cell;
StoreDetailFacilityCell.m
@implementation StoreDetailFacilityCell
@synthesize storeDetailFacilityCellView;
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
CGRect tzvFrame = CGRectMake(0.0, 0.0, self.contentView.bounds.size.width, self.contentView.bounds.size.height);
storeDetailFacilityCellView = [[StoreDetailFacilityCellView alloc] initWithFrame:tzvFrame];
[self.contentView addSubview:storeDetailFacilityCellView];
}
return self;
}
-(void)configureCell:(NSDictionary *)storeFacility atRow:(NSIndexPath *)row {
NSLog([NSString stringWithFormat:@"updating %@ at row %i",[storeFacility objectForKey:@"facilityKey"],row.row]);
storeDetailFacilityCellView.storeFacility = storeFacility;
}
-(void)redisplay {
[storeDetailFacilityCellView setNeedsDisplay];
}
-(void)dealloc {
[storeDetailFacilityCellView release];
[super dealloc];
}
StoreDetailFacilityCellView.m
@implementation StoreDetailFacilityCellView
@synthesize highlighted;
@synthesize editing;
@synthesize storeFacility;
-(id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
}
return self;
}
-(void)setHighlighted:(BOOL)lit {
if (highlighted != lit) {
highlighted = lit;
[self setNeedsDisplay];
}
}
-(void)drawRect:(CGRect)rect {
UIColor *mainTextColor = nil;
UIFont *mainFont = [UIFont systemFontOfSize:14];
if (self.highlighted) {
mainTextColor = [UIColor whiteColor];
} else {
mainTextColor = [UIColor blackColor];
}
if (!self.editing) {
CGPoint point;
[mainTextColor set];
point = CGPointMake(80, 9);
[[storeFacility objectForKey:@"facilityTitle"] drawAtPoint:point withFont:mainFont];
}
}
-(void)dealloc {
[storeFacility release];
[super dealloc];
}
檢查這個線程: http://stackoverflow.com/questions/16425122/ios-cellforrowatindexpath-cells-are-getting-mixed-up –
檢查這個線程 http://stackoverflow.com/questions/ 16425122/ios-cellforrowatindexpath-cells-getting-getting-mixed-up –