I would like to display an UIView above my tableview, for testing purposes I have used a Searchbar (to eliminate any possible problems with my code).
My开发者_开发知识库 setup:
Tab bar controller MyCustomTableViewController View TableView (for customizing cell height) SearchbarI have positioned the searchbar at the top of the "window" and pulled down the tableview so that it is positioned directly below the searchbar.
So in IB everything looks great. But when I start the application the tableview takes up the whole screen, and the searchbar is nowhere to be found.I'm quite new to IPhone development so there might be a very simple solution(?).
/JimmyThe really simple solution is to:
- Create a custom UIViewController subclass that implements
UITableViewDelegate
andUITableViewDataSource
just likeUITableViewController
does. Also add aUITableView
outlet. - In the XIB file, put your searchbar and
UITableView
inside the view controller's view. - Connect the table view to the
tableView
outlet in your customUIViewController
- Connect the
UITableView
's delegate and datasource to the File's Owner (your customUIViewController
that implements the right delegates)
You now have a custom view controller that works just like a UITableViewController
except you have total control over it's layout. You implement the delegates in the same way.
If you're MyCustomTableViewController is actually a UITableViewController then you'll notice in IB that the "view" outlet points directly to your UITableView instead of the root UIView in IB. This is the default behavior for UITableViewController objects. Simply redirect the "view" outlet to the root UIView and everything should display correctly.
精彩评论