iphoneuitableview单元正在运行';卡住';和快速滚动混合在一起
基于此,我在这里采用了数字5的结构,以创建自定义绘制的表格单元。这是伟大的工作,滚动速度是梦幻般的现在相比,当我使用笔尖 然而,它引入了一个我无法理解的错误——如果我在屏幕上快速滚动,单元格内容似乎会混淆,单元格将显示应该出现在另一个单元格中的内容。有时多个单元格甚至会显示相同的内容。如果我点击并按住单元格,就好像我正在选择它一样,它会再次刷新到正确的内容。我已经验证了从表的viewcontroller中的数组向正确的单元格传递正确的数据,所以我猜这是图形上的问题 任何帮助都会很好,我无法计算出我对样品做了哪些不同。相关代码如下: 查看控制器iphoneuitableview单元正在运行';卡住';和快速滚动混合在一起,iphone,objective-c,uitableview,scroll,Iphone,Objective C,Uitableview,Scroll,基于此,我在这里采用了数字5的结构,以创建自定义绘制的表格单元。这是伟大的工作,滚动速度是梦幻般的现在相比,当我使用笔尖 然而,它引入了一个我无法理解的错误——如果我在屏幕上快速滚动,单元格内容似乎会混淆,单元格将显示应该出现在另一个单元格中的内容。有时多个单元格甚至会显示相同的内容。如果我点击并按住单元格,就好像我正在选择它一样,它会再次刷新到正确的内容。我已经验证了从表的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;
@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];
}
@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];
}
StoreDetailFacilityCell.m
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;
@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];
}
@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];
}
StoreDetailFacilityCellView.m
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;
@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];
}
@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];
}
我看到的一个不一致之处是:在
tableView:cellForRowAtIndexPath:
中,您正在调用-[StoreDetailFacilityCellView initWithFrame:reuseIdentifier:
,它应该是initWithStyle:reuseIdentifier:
我最终解决了这个问题,我没有调用setNeedsDisplay在单元格的视图上,现在工作得很好。很好,我已经将此更改为与样本匹配,但不幸的是,我仍然存在相同的问题。检查此线程:检查此线程