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
how to scroll uitableview, and section header in the top, visible and scroll to
提问by alex willrock
i have UITableview
with multiple sections with style group, and light custom header view
after scroll, header not stick in the top, and invisible
我有UITableview
多个带有样式组的部分,滚动后自定义标题视图很轻,标题不粘在顶部,并且不可见
i need scroll UITableview
and 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];