我正在使用 UITableView 来显示数据。我在每个单元格内放置了 1 个 UILabel。我想在滚动时隐藏这些 UILabel。我试过这个,但什么也没发生。
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
homeButton.userInteractionEnabled = NO;
HomeCell *cell = [[HomeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.timeLeft.hidden = YES;
}
谢谢。
最佳答案
我会使用 NSNotification
为了这。
在 HomeCell
awakeFromNib
中的类方法做...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showLabel) name:@"ShowLabelsInCells" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideLabel) name:@"HideLabelsInCells" object:nil];
然后创建方法
showLabel
和 hideLabel
.然后在
UITableViewController
您可以观看 ScrollView 滚动(和停止滚动)并调用...[[NSNotificationCenter defaultCenter] postNotificationName:@"ShowLabelsInCells" object:nil];
和...
[[NSNotificationCenter defaultCenter] postNotificationName:@"HideLabelsInCells" object:nil];
当你需要它们时。
无需遍历单元格。
关于ios - 滚动时在 UITableViewCell 中隐藏 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18051940/