Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
}
like image 917
alex willrock Avatar asked Aug 21 '14 06:08

alex willrock


People also ask

How do I scroll the header along with UITableView?

If you have a single header in the table then you can use tableHeaderView as below: tableView. tableHeaderView = Header; Or if you have multiple header in table than you need to use Group table instead of plain table.

How do I scroll to top tableView?

To scroll to the top of our tableview we need to create a new IndexPath . This index path has two arguments, row and section . All we want to do is scroll to the top of the table view, therefore we pass 0 for the row argument and 0 for the section argument. UITableView has the scrollToRow method built in.

Is UITableView scrollable?

UITableView scrolls back because it's content size is equal to it's frame (or near to it). If you want to scroll it without returning you need add more cells: table view content size will be large then it's frame.

What is header in swift?

For output message, the basic header identifies the application through which SWIFT has processed the message. The basic header also identifies the type of output data, the receiving logical terminal, and (if required) the output session number and output sequence number.


1 Answers

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];

enter image description hereenter image description here

Apple Documentation

like image 195
Vijay-Apple-Dev.blogspot.com Avatar answered Oct 05 '22 03:10

Vijay-Apple-Dev.blogspot.com