views:

613

answers:

2

I have an UITableView and I did put an UISearchbar on it. What I want to achieve is that if a user is going to scroll i want the UISearchbar element to be fixed on the top, plus I want the first row of the UITableView fixed as well. Is there any sample code for this ?

So far every sample I found the UISearchbar wasn't fixed at the top, if you scroll it disappears. One way to get the UISearchbar element fixed could be, if I put an UIView under both elements (UITableView and UISearchbar) and put those two consecutively among themselves (just a thought of me don't know if this actually is working). However i'm not sure if this is the appropriate way to go and it also wouldn't fix that I want the first row fixed as well.

I'm kinda new to this stuff would be glad if someone could point me in the right direction, thank you.

+3  A: 

For the fixed search bar: just make it a sibling of the tableView.

For the fixed first row: maybe make it the section header and have only 1 section, or make it a sibling view.

jessecurry
how can i make the search bar as sibling ?
kukudas
you'll want your view controller to subclass UIViewController instead of UITableViewController, then you'll have a UIView as your view instead of a UITableView. In that UIView you'll want to add the SearchDisplayController and a UITableView. You'll then need to implement the UITableViewDataSource and UITableViewDelegate protocols.
jessecurry
A: 

you mean i have to change

@interface RootViewController : UITableViewController

as @interface RootViewController : UIViewController

and all self.tableView.tableHeaderView = searchBar;  like 
self.uiView.tableHeaderView = searchBar;
ram