Reputation: 996
i have UITableview
with multiple sections with style group, and light custom header view
after scroll, header not stick in the top, and invisible
i need scroll UITableview
and section header stick in the top view and visible, like phonebook
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;
}
Upvotes: 9
Views: 14828
Reputation: 25692
UITableViewStyleGrouped = The section headers and footers do not float.
UITableViewStylePlain = Any section headers or footers are displayed as inline separators and float when the table view is scrolled
You just change the UITableViewStyle to UITableViewStylePlain
Then to scroll to particular row and section programatically you could use this below UITableViewMethod method.
//Scroll to First row in 2 section
[yourTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]
atScrollPosition:UITableViewScrollPositionTop animated:YES];
Upvotes: 20