我创建了一个自定义的UITableView单元,它有4-5个不同的组件。有时我会根据CGRectMake创建UIViews,并根据一些x,y坐标计算来定位一些UIImages。 Everthing工作正常cos cellForRowAtIndexPath每次创建一个新的单元格。但是当我要重用基于“dequeueReusableCellWithIdentifier”的单元时,UI会变得混乱。之前的矩形使得从未被擦除,早期的UIViews的定位也表现怪异。虽然单元格索引是变化,但它并不反映绘制的UIImages的协调。每次关闭UITableViewCell cellForRowAtIndexPath调用
在每个单元格中创建UITableViewCellForRowAtIndexPath在3GS和4G中工作正常,但它真的非常烦人,而且它在3G中非常慢。我怀疑这种行为是因为在每次调用中创建了这个cellForRowAtIndexPath。所以任何人都可以帮助我找出这个问题。
这就是我现在要做的。
CustomNoteCell *cell = nil;
if (cell == nil) {
cell = (CustomNoteCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomNoteCell" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UITableViewCell class]]) {
cell = (CustomNoteCell *) currentObject;
break;
}
}
}
//rest of the codes go here like
CGSize maximumLablelSize = CGSizeMake(296, 1000);
CGSize expectedLabelSize = [alue sizeWithFont:cell.customCellNoteText.font constrainedToSize:maximumLablelSize lineBreakMode:cell.customCellNoteText.lineBreakMode];
CGRect newFrame = cell.customCellNoteText.frame;
newFrame.size.height = expectedLabelSize.height;
cell.customCellNoteText.frame = newFrame;
cell.customCellNoteText.text = noteValue;
cell.uiViewContrlloer = self;
CGRect addressRect = cell.address.frame;
addressRect.origin.y = newFrame.origin.y + newFrame.size.height + 10;
cell.address.frame = addressRect;
谢谢
是。我已经发布了工作示例。在这种情况下,它工作正常。但在3G中有缓慢的表现,但在3GS和4G上表现完美。但是,当我在if(cell == nil)之前将单元出队时,我得到了我讨论的问题。所以这是我的问题。我想在该线以上出院,它应该按预期工作,但目前尚不能。 – Dilshan 2010-11-06 07:11:47
你可以发布你的实际代码,将无法正常工作,并与格式?我的眼睛现在受伤了... – tia 2010-11-06 07:22:34
对不起。格式化它。 – Dilshan 2010-11-06 14:23:24