【问题标题】:Is there a way to determine what is the "top" section header of a UITableView?有没有办法确定 UITableView 的“顶部”部分标题是什么?
【发布时间】:2011-07-28 18:31:42
【问题描述】:

有没有办法确定 UITableView 的“顶部”部分标题是什么?

对于“顶部部分标题”,我指的是粘在 UITableView 边界顶部的部分标题。

【问题讨论】:

    标签: iphone uitableview sections


    【解决方案1】:

    您可以使用以下方法获取部分编号:

    NSUInteger sectionNumber = [tableView indexPathForCell: [[[tableView visibleCells] objectAtIndex: 0] section]];
    

    希望对你有帮助。

    【讨论】:

    • 我认为这个答案最好地涵盖了它,尽管在过渡期间会发生一些棘手的事情,而两个标题一起在顶部可见......
    • 我使用了类似的方法,但是正如 Alex 所指出的那样,它不符合我的需要,因为我需要知道什么是顶部可见的组部分标题,并且此方法在您拥有超过一次可见 1 个部分标题。
    • 答案 NSUInteger sectionNumber = [tableView indexPathForCell: [[[tableView visibleCells] objectAtIndex: 0] section]];是错的。它是 NSInteger sectionNumber = [[tableView indexPathForCell:[[menu visibleCells] objectAtIndex:0]] section];
    【解决方案2】:

    您需要使用 -(UIView) viewForHeaderInSection 方法。这将允许您使用自己的 UI 视图作为表格视图部分的标题。

    【讨论】:

    • 这是一个 UITableViewDelegate 方法。
    • viewForHeaderInSection 不是“粘性”:-)
    • 它停留在当前屏幕部分。就像在通讯录或音乐应用中一样。
    【解决方案3】:

    如果您指的是 TABLE 标头(和 TABLE 页脚),而不是 SECTION 页眉/页脚,那么您可以通过 tableHeaderView 访问它,这是 UITableView 的一个属性

    tableHeaderView Returns an accessory view that is displayed above the table.
    
    @property(nonatomic, retain) UIView *tableHeaderView
    

    如果你想要SECTION头,那么你需要通过实现UITableViewDelegate方法-tableView:viewForHeaderInSection:来创建它

    tableView:viewForHeaderInSection: Asks the delegate for a view object to display in the header of the specified section of the table view.
    
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    

    【讨论】:

    • 我需要一种方法来获取顶部“粘性”的组部分标题的当前 NSUInteger。
    • 也许“粘性”部分的图片会有所帮助?在这里不确定,因为“节标题”不粘,并与各自的部分一起滑入和滑出
    猜你喜欢
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 2015-04-22
    • 2014-07-23
    • 2021-09-08
    相关资源
    最近更新 更多