Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何滚动uitableview和顶部的节标题,可见并滚动到_Ios_Objective C_Xcode_Uitableview - Fatal编程技术网

Ios 如何滚动uitableview和顶部的节标题,可见并滚动到

Ios 如何滚动uitableview和顶部的节标题,可见并滚动到,ios,objective-c,xcode,uitableview,Ios,Objective C,Xcode,Uitableview,我有UITableview,其中包含多个带有样式组的部分,以及轻型自定义标题视图 滚动后,标题不会粘在顶部,且不可见 我需要滚动UITableview并在顶部视图中粘贴节头,使其可见,如电话簿 如何使之成为现实 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc] initWithFram

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


对于没有行的节,解决方案不起作用