接受的方法似乎很髒,它只是使一堆新的細胞與壞的一起存儲。這裏有幾個解決方案取決於你的情況:
1. 首先,對於問題中描述的情況,你不應該轉儲你的單元格並在每個週期創建新的視圖。您需要標記您的視圖,然後從電池拿回來的時候,當你得到一個複用小區:
- (UITableViewCell*) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath {
UITableViewCell *cell = [tableView dequeueResuableCellWithIdentifier:SOME_ID];
if(!cell) {
cell = [[UITableViewCell alloc] init];
UIView *myView = [[UIView alloc] init];
cell.backgroundView = myView;
[myView setTag:5]; //<------
}
UIView *myView = [cell viewWithTag:5]; //<------
if ((indexPath.row % 2) == 0)
myView.backgroundColor = [UIColor greenColor];
else
myView.backgroundColor = [UIColor whiteColor];
return cell;
}
//then just reload the tableview.
2. ...甚至更好,爲什麼不使用電池backgrouncolor和更新,沒有創建一個視圖。
3. 確實清除舊的緩存單元格,它只是重新創建UITableView對象。
4. 在大多數情況下,您不需要銷燬這些單元格,只需跟蹤元素並在獲得可重用單元格後更新它們。您可以標記所有元素,保存數組引用,找到它們視圖層次結構......我確定了其他一些方法。
5。 繼承人一個襯墊直接清除所有細胞,雖然不是最好的做法惹這樣的物體的內部結構,因爲他們可能在未來的版本中改變:
[(NSMutableDictionary*)[tableview valueForKey:@"_reusableTableCells" ] removeAllObjects];
做我的回答幫助? – 2010-07-07 20:22:37