【问题标题】:iOS: UITableview header hide behind the view on scroll upiOS:UITableview 标头在向上滚动时隐藏在视图后面
【发布时间】:2016-05-19 06:50:09
【问题描述】:

我的 tableview 控制器中有一个自定义分段控件,tableview 的标题中有一个搜索栏。当我向上滚动到最后一个单元格时,tableview 会弹回来。但问题是:我的搜索栏隐藏在分段控件后面,视图底部出现一个空白。我希望如果用户向上滚动表格视图,它会反弹并返回到之前的位置,如第一个屏幕截图所示。

这是我的分段控制代码:

self.projectSegmentControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"Active Projects", @"All Projects", nil]];
    [self.projectSegmentControl addTarget:self action:@selector(actionSelectProject) forControlEvents:UIControlEventValueChanged];
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width -20;
    self.projectSegmentControl.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-screenWidth-5,10, screenWidth, 30.0);
    _segmentControlView = [[UIView alloc] initWithFrame: CGRectMake(0,60, screenRect.size.width,47.0)];
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    _segmentControlView.backgroundColor = [UIColor whiteColor];
    self.projectSegmentControl.backgroundColor = [UIColor whiteColor];
    [_segmentControlView addSubview:self.projectSegmentControl];
    [appDelegate.window addSubview:_segmentControlView];
    self.projectSegmentControl.selectedSegmentIndex = 0;
    CGFloat screenHeight = screenRect.size.height;
    if(screenHeight==480 || screenHeight==568)
    {
        CGPoint newOffset = CGPointMake(0, -[self.tableView  contentInset].top);
        [self.tableView setContentOffset:newOffset animated:YES];
    }

    UIFont *font = [UIFont fontWithName:@"Avenir" size:12.0f];
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    [_projectSegmentControl setTitleTextAttributes:attributes forState:UIControlStateNormal];

这是tableview出现时的截图:

当我向上滚动 tableview 反弹但搜索栏隐藏在分段控件后面时。

PS:如果需要,我会添加代码。提前致谢

【问题讨论】:

  • 请发布您的代码
  • 我已经添加了我的分段控件的代码。如果你想要更多的代码,我会添加。

标签: ios objective-c iphone uitableview uisearchbardisplaycontrol


【解决方案1】:

上面的帖子我假设你正在使用

UITableViewController(不是UIViewController

您已在表格视图的标题中添加了搜索栏。

然后您以编程方式创建了一个分段控制器并添加到窗口中

 CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width -20;
    self.projectSegmentControl.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-screenWidth-5,10, screenWidth, 30.0);
    _segmentControlView = [[UIView alloc] initWithFrame: CGRectMake(0,60, screenRect.size.width,47.0)];
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

所以当你滚动表格时,显然标题也会随之移动。所以它隐藏在分段控件后面。

解决方案

步骤1.创建uiviewcontroller(不是uitableviewcontroller)
步骤 2. 在视图中添加分段控件
步骤 3. 在分段控件下方添加静态搜索栏。 步骤 4.so 滚动 tableview 时,分段控件不会被隐藏

希望这会对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多