在iOS5中将子视图添加到UITableViewCell
在iOS5中,单元格是自动分配的,因此向其中添加子视图时存在问题, 因为每次单元格重新加载时,子视图都会添加到其中 我现在要做的是检查子视图并在添加新视图之前将其删除,如下所示:在iOS5中将子视图添加到UITableViewCell,ios5,uitableview,Ios5,Uitableview,在iOS5中,单元格是自动分配的,因此向其中添加子视图时存在问题, 因为每次单元格重新加载时,子视图都会添加到其中 我现在要做的是检查子视图并在添加新视图之前将其删除,如下所示: for (UIView *subview in cell.subviews) { if ([subview isKindOfClass:MarqueeLabel.class]) { [subview removeFromSuperview]; } } 有谁有更好的解决方案吗?在Cel
for (UIView *subview in cell.subviews) {
if ([subview isKindOfClass:MarqueeLabel.class]) {
[subview removeFromSuperview];
}
}
有谁有更好的解决方案吗?在CellForRowatineXpath:delegate protocol方法中,您应该有并且肯定已经实现了该方法,请尝试以下方法:
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];
}
iOS5中的单元格始终不是零。cell.subviews=nil是不可能的。