2012-03-16 64 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

相關問題