ios - 当部分没有行时确定 UITableView 的可见部分

标签 ios objective-c uitableview

我正在尝试确定哪些部分当前在我的 UITableView 中可见。但是,有时我的部分没有行,只显示它们的部分标题。有没有办法确定,也许通过使用节标题,当前正在显示我的 UITableView 中的哪些节?询问 -(NSArray *)indexPathsForVisibleRows 无法确定该部分,因为没有实际可见的行,只有部分标题。

最佳答案

我能想到的最好办法是使用 contentOffset 和 frame.size 来计算可见矩形并遍历调用 rectForSection: 的每个部分并查看哪些部分相交。像这样的东西:

-(NSIndexSet*)visibleSections
{
    NSMutableIndexSet*  indexSet = [NSMutableIndexSet new];
    CGRect              visible = self.tableView.bounds;

    for(NSInteger section = 0 ; section < [self numberOfSections])
    {
        CGRect          sectBounds = [self.tableView rectForSection:section];

        if(CGRectIntersectsRect(sectBounds, visible))
        {
            [indexSet addIndex:section];
        }
    }

    return indexSet;
}

关于ios - 当部分没有行时确定 UITableView 的可见部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22872042/

相关文章:

android - 如何访问适用于 iOS 和 Android 的 Xamarin.Forms 中的目录路径?

ios - 从文本字段中移除焦点

ios - Tabbar > Split > NavigationController 结果为 [MasterViewController topViewController] : unrecognized selector sent to instance: Core Data

ios - 如何在iOS中实现Android的getViewById?

ios - 如何使用 PushNotification 插件在 Xamarin Forms for IOS 中实现推送通知

ios - 如何在实例方法中调用类型方法

ios - 如何在iOS中绘制梯形?

objective-c - 应用程序因 [WAKScrollView canBecomeFocused] : unrecognized selector sent to instance 崩溃

iphone - 检索在 sqlite 数据库中插入的所有行,并在包含标签的 TableView 单元格中显示为具有不同部分的 subview

ios - 实例化 Controller 时准备 segue 崩溃