![](/img/trans.png)
[英]Swift 2.0 UITableView Section Header scroll to top when tapped
[英]how to scroll uitableview, and section header in the top, visible and scroll to
我有帶有樣式組的多個部分的UITableview
,並且滾動后顯示了自定義標題視圖,標題沒有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;
}
UITableViewStyleGrouped =節的頁眉和頁腳不浮動。
UITableViewStylePlain =滾動表視圖時,任何節的頁眉或頁腳都將顯示為行內分隔符並浮動
您只需將UITableViewStyle更改為UITableViewStylePlain
然后,以編程方式滾動到特定的行和節,可以在UITableViewMethod方法下面使用此方法。
//Scroll to First row in 2 section
[yourTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]
atScrollPosition:UITableViewScrollPositionTop animated:YES];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.