One of the screens in my iPhone app is a UITableView that has a search bar in the table header. I want the search bar to be hidden until the user pulls it down, so I use this line in my viewDidLoad method:
[self.tableView setContentOffset:CGPointMake(0,40) animated:NO];
This correctly displays the tableView with the header scrolled off the top of the screen.
My problem occurs when I try to delete a row using this method:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:myIndexPath] withRowAnimation:UITableViewRowAnimationRight];
When that line executes, it correctly slides the row off the right side of the screen. If the table only contains a few rows, though, the table header (with my search bar) is scrolled down to fill up the space freed up by the newly deleted row. I don't want this to happen. I want the header to remain hidden until a user scrolls it down with his finger.
If the tableView has enough lines to fill the window, the table fills up from the bottom and the header remains hidden. The problem only occurs when the screen is not completely filled with rows.
Any idea on how I can force the UITableView to not display the table header when I delete a row?
Addendum: I discovered that the same thing happens when I put the UITableViewController into editing mode using code like this:
[self setEditing:NO animated:YES];
It goes into editing mode, displays the red "delete row" circles, and displays the table header. Maybe it's something with the animations.