can*_*boy 0 iphone objective-c uitableview
我有一个带有单元格的UItableview.有些细胞有uilabels,有些细胞有uibuttons.只要数组中的第一个字符为"^",就会创建UI按钮.然而,当我向下滚动(出现在uilabel上方)时,uibuttons重复...然后当我向上滚动时,在uilabels上相乘.任何线索为什么?
实际上,每次滚动部分并加载行时,所有标签和ui组件都会在运行时添加到单元格中,每次单元格出列时都需要清除单元格中添加的所有视图,而不是无,请参阅以下示例:
static NSString *CellIdentifier;
CellIdentifier = [NSString stringWithFormat:@"Cell%d%d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
/*
* THIS IS FOR OS VERSION 2.2 THE OLDER VERSION
* cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
*/
} else {
for (UIView* tempView in cell.contentView.subviews) {
[tempView removeFromSuperview];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4252 次 |
| 最近记录: |