UITableView是iOS中重要的控件,UITableView繼承自UIScrollView,支持垂直滾動,而且性能極好,UITableViewCell可以復用。
cell的重用
static NSString *reuseID = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseID];
}
1、給cell做個標記,當cell出屏幕(不用之后)把cell對象,存儲在特定標示的緩存池,當tableView加載下一個數據的時候,從緩存池中取出 空閑的標記cell。
2、如果緩存池中有空余的cell,會重新配置這個cell數據。給tableView顯示。如果沒有空余的cell,就重新創建。
在iOS開發中,如果tableViewCell是變化的,復用cell會引起的視圖重疊。
解決方法:
for(UIView *view in [cell subviews]){
[view removeFromSuperview];
}
或
static NSString *reuseID = @"cell";
UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseID];