2012-03-16 62 views
0

在iOS5中,单元格自动分配,因此添加子视图时出现问题,因为每次单元重新加载子视图时都会添加子视图。在iOS5中将子视图添加到UITableViewCell中

我现在要做的是检查子视图,并添加新的之前删除它,这样的:

for (UIView *subview in cell.subviews) { 
    if ([subview isKindOfClass:MarqueeLabel.class]) { 
     [subview removeFromSuperview]; 

    } 
} 

没有任何人有更好的解决办法?

中的cellForRowAtIndexPath

回答

0

:你应该有,肯定已经实施了委托协议方法,试试这个:

 if (cell) { 
    // This if statement is declaring that the cell is non-zero and valid. All your activity with the cell should be done here, add the following: 
cell.imageView.image = nil; 
// or 
cell.imageView = nil; 
// or most likely in your case 
cell.subviews = nil; 
// Then assign your subviews/image or whatever. This way it refreshes each time. 

此外,你出列像下面的tableViewCells:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:@"cell"] 
      autorelease]; 
} 
+0

细胞总是在iOS5中不是零。 cell.subviews =零是不可能的。 – Shmidt 2012-03-18 14:06:46

相关问题