1

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

这里是我的分段控制的代码:

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出现时: enter image description here

当我滚动tableview中反弹,但搜索栏是分段控制的背后隐藏。

enter image description here

PS:如果需要的话,我会添加代码。在此先感谢

+0

请发布您的代码 – SeanChense

+0

我已经添加了我的分段控制代码..如果你想要更多的代码,我会添加。 –

回答

0

与上述职位我假设你正在使用

UITableViewController(不UIViewController

您已经添加在tableview中的报头中的搜索栏。

然后编程,你已经创建了一个分段控制器和窗口添加

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

所以当你滚动表,显然也将头与它一起移动。所以它隐藏在分段控制之后。

SOLUTION

步骤1.创建的UIViewController(不可的UITableViewController)
步骤2.加入视图
步骤3.分段控制添加分段控制之下的静态搜索栏。 step 4.so滚动tableview时,分段控件不会被隐藏

希望这会对你有帮助。

相关问题