ios - 滚动时在 UITableViewCell 中隐藏 UILabel

标签 ios objective-c uitableview

我正在使用 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];

然后创建方法showLabelhideLabel .

然后在UITableViewController您可以观看 ScrollView 滚动(和停止滚动)并调用...
[[NSNotificationCenter defaultCenter] postNotificationName:@"ShowLabelsInCells" object:nil];

和...
[[NSNotificationCenter defaultCenter] postNotificationName:@"HideLabelsInCells" object:nil];

当你需要它们时。

无需遍历单元格。

关于ios - 滚动时在 UITableViewCell 中隐藏 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18051940/

相关文章:

swift - 图像无法在表格 View 中显示

objective-c - UITabBarController 中的 UINavigationController - 转到选项卡选择的顶部

php - iOS 无法通过 PHP 在 iPhone 应用程序和 MySQL 数据库之间进行通信

iphone - 使用 CLGeocoder 将 NSString 纬度/经度坐标转换为城市、州和时区

objective-c - 核心数据内存管理

ios - 使用自动布局时如何知道 UITableViewCell 的宽度?

html - 将Youtube视频嵌入HTML for iOS

ios - 动态更新 UITextView autocapitalizationType

iOS 7/8 Objective C - 将混合模式应用于 View

iphone - iOS-如何计算UITableViewCell的默认textLabel的宽度?