static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSArray *subviews = [[NSArray alloc] initWithArray:cell.subviews];
for (UIView *subview in subviews) {
[subview removeFromSuperview];
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSArray *subviews = [[NSArray alloc] initWithArray:cell.subviews];
for (UIView *subview in subviews) {
[subview removeFromSuperview];
}
本文介绍UITableView中UITableViewCell的重用机制实现方法。通过设置静态NSString CellIdentifier,并使用dequeueReusableCellWithIdentifier方法来获取可重用的UITableViewCell。如果cell不存在,则创建新的UITableViewCell。此外,还展示了如何移除UITableViewCell的所有子视图。
1313

被折叠的 条评论
为什么被折叠?



