【问题标题】:how to scroll uitableview, and section header in the top, visible and scroll to如何滚动uitableview和顶部的部分标题,可见并滚动到
【发布时间】:2014-08-21 06:55:26
【问题描述】:

我有 UITableview 有多个带有样式组的部分,以及轻量级的自定义标题视图 滚动后,标题不粘在顶部,不可见

我需要滚动 UITableview 并将部分标题粘贴在顶部视图中并且可见,例如电话簿

如何制作?

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320,50)];
    UILabel *labelHeader = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, 120, 40)];
    labelHeader.text = [[_groups objectAtIndex:section] objectForKey:@"nameExerciseGroup"];
    labelHeader.textColor = [UIColor blackColor];
    [labelHeader setFont:[UIFont systemFontOfSize:20]];

[headerView addSubview:labelHeader];
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}

【问题讨论】:

    标签: ios objective-c xcode uitableview


    【解决方案1】:

    UITableViewStyleGrouped = 部分页眉和页脚不浮动。

    UITableViewStylePlain = 任何部分的页眉或页脚都显示为内联分隔符并在表格视图滚动时浮动

    您只需将 UITableViewStyle 更改为 UITableViewStylePlain

    然后以编程方式滚动到特定的行和部分,您可以使用下面的 UITableViewMethod 方法。

    //Scroll to First row in 2 section
    [yourTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]
                         atScrollPosition:UITableViewScrollPositionTop animated:YES];
    

    Apple Documentation

    【讨论】:

    • 解决方案在没有行的部分的情况下不起作用
    猜你喜欢
    • 2012-04-05
    • 2010-10-18
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 2014-10-20
    相关资源
    最近更新 更多