views:

591

answers:

2

Hi
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)
            Searchbar

I 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(?).
/Jimmy

A: 

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.

Matthew McGoogan
MyCustomTableViewController is a class derrived from UITableViewController since I want the tableview to contain custom cells.It seems that the "View" outlet is missing on my MyCustomTableViewController,any Idea on why, and how to get it back?
Jimmy Engtröm
Uh no. the `UITableViewController` expects the view to point to a `UITableView` and it will completely fail if you change it to point to some other type of view.
St3fan
Of course. I forgot that I typically change the UITableViewController superclass to be a UIViewController as well. That way I don't have to write in the table view delegate/datasource methods.
Matthew McGoogan
+4  A: 

The really simple solution is to:

  • Create a custom UIViewController subclass that implements UITableViewDelegate and UITableViewDataSource just like UITableViewController does. Also add a UITableView 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 custom UIViewController
  • Connect the UITableView's delegate and datasource to the File's Owner (your custom UIViewController 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.

St3fan
Worked like a charm =).(to clarify: "in the XIB file" is where you place your custom UIView not the custom UIView's XIB as I thought first)thanks
Jimmy Engtröm