2010-11-06 64 views
0

我创建了一个自定义的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; 

谢谢

回答

1

我觉得你把你的离队细胞的呼叫在错误的地方。你应该把它放在if (cell == nil)之前。

+0

是。我已经发布了工作示例。在这种情况下,它工作正常。但在3G中有缓慢的表现,但在3GS和4G上表现完美。但是,当我在if(cell == nil)之前将单元出队时,我得到了我讨论的问题。所以这是我的问题。我想在该线以上出院,它应该按预期工作,但目前尚不能。 – Dilshan 2010-11-06 07:11:47

+0

你可以发布你的实际代码,将无法正常工作,并与格式?我的眼睛现在受伤了... – tia 2010-11-06 07:22:34

+0

对不起。格式化它。 – Dilshan 2010-11-06 14:23:24

0

正如tia提到的那样,你的细胞总是会变成零。你应该尽早出队。

CustomNoteCell *cell = (CustomNoteCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (! cell) { 
    cell = [[[CustomNoteCell alloc] initWithReuseIdentifier:CellIdentifier] autorelease]; 

...

+0

谢谢Joshpaul。当我要重用基于“dequeueReusableCellWithIdentifier”的单元格时,UI会变得混乱。这是问题。 – Dilshan 2010-11-08 05:02:14

+0

什么是“搞砸了?”这种方法会发生什么? static NSString * CellIdentifier = @“CustomNoteCell”; CustomNoteCell * cell =(CustomNoteCell *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(!cell) cell = [[[NSBundle mainBundle] loadNibNamed:@“CustomNoteCell”owner:self options:nil] lastObject]; } //定制单元格... – joshpaul 2010-11-10 16:46:10

+0

这里的问题是定位出错。它在每个单元格中随机抽取内容。 – Dilshan 2010-11-16 10:12:27

相关问题