我有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;
}
答案 0 :(得分:19)
UITableViewStyleGrouped =节页眉和页脚不会浮动。
UITableViewStylePlain =任何部分页眉或页脚都显示为内联分隔符,并在滚动表格视图时浮动
您只需将 UITableViewStyle更改为UITableViewStylePlain
然后以编程方式滚动到特定的行和节,您可以在UITableViewMethod方法下面使用它。
//Scroll to First row in 2 section
[yourTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]
atScrollPosition:UITableViewScrollPositionTop animated:YES];