I have a custom segmented control in my tableview controller and a search bar in header of tableview. When i scroll up till last cell, tableview bounce back. But problem is: My search bar hides behind the segmented control and a white space appears on bottom of the view. I want that if user scroll up the tableview it bounce and came back to its previous position as shown in first screenshot.
Here is code of my Segmented Control :
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];
It is the screenshot when tableview appears :
When i scroll up tableview bounce back but search bar is hide behind the segmented control.
PS: I will add the code if needed. Thanks in advance