我創建了一個自定義的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