【发布时间】:2010-11-06 06:28:25
【问题描述】:
我创建了一个自定义 UITableView 单元格,它有 4-5 个不同的组件。有时我从 CGRectMake 创建 UIViews,有时基于一些 x、y 坐标计算我定位一些 UIImages。一切正常,因为 cellForRowAtIndexPath 每次创建一个新单元格。但是,当我要基于“dequeueReusableCellWithIdentifier”重用单元格时,UI 会变得一团糟。以前的 rect 制作永远不会被删除,并且早期 UIViews 的定位也表现得很奇怪。尽管单元格索引是变化的,但它并不反映绘制的 UIImages 的协调性。
在每个 cellForRowAtIndexPath 中创建 UITableViewCell 在 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;
谢谢
【问题讨论】:
标签: iphone iphone-sdk-3.0 uitableview ios4