Monday 19 August 2013

Problems with UISearchBar not working like in stock apps (scrolling under UINavigationBar)

Problems with UISearchBar not working like in stock apps (scrolling under
UINavigationBar)

I've got a problem in that I cannot get my UISearchBar to scroll
underneath my UINavigationBar.
-(void)awakeFromNib
{
[super awakeFromNib];
self.tableView.tableHeaderView = self.taskSearchBar;
}
-(UIView*)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
{
return self.taskSearchBar;
}
-(CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section
{
return 44;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tableView.frame = self.view.bounds;
// Load our table with current data
[self.tableView reloadData];
// Tuck UISearchBar under navigation bar
self.tableView.contentOffset = CGPointMake(0,
self.taskSearchBar.frame.size.height);
}
I've spent a LOT of time searching through SO to try to find relevant
discussions.
This one, for example, makes it sound OH SO SIMPLE: Scroll UITableView so
that the header isn't visible
I was previously able to get this to work when creating everything from
Story Board, but I can no longer do that due to the nature of my app - I
had to break things out to have a parent UIView to the UITableView which I
was unable to do while using a UITableViewController.
Any help on this would be MUCH appreciated!!!

No comments:

Post a Comment