xcode 如何滚动 uitableview 和顶部的部分标题,可见并滚动到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25420015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:25:33  来源:igfitidea点击:

how to scroll uitableview, and section header in the top, visible and scroll to

iosobjective-cxcodeuitableview

提问by alex willrock

i have UITableviewwith multiple sections with style group, and light custom header view after scroll, header not stick in the top, and invisible

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

i need scroll UITableviewand section header stick in the top view and visible, like phonebook

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

how to make it's ?

如何制作它?

- (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;
}

回答by Vijay-Apple-Dev.blogspot.com

UITableViewStyleGrouped = The section headers and footers do not float.

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

UITableViewStylePlain = Any section headers or footers are displayed as inline separators and float when the table view is scrolled

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

You just change the UITableViewStyle to UITableViewStylePlain

您只需将UITableViewStyle更改 为 UITableViewStylePlain

Then to scroll to particular row and section programatically you could use this below UITableViewMethod method.

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

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

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

Apple Documentation

苹果文档