我在我的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中反弹,但搜索栏是分段控制的背后隐藏。
PS:如果需要的话,我会添加代码。在此先感谢
请发布您的代码 – SeanChense
我已经添加了我的分段控制代码..如果你想要更多的代码,我会添加。 –