4

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

2 Answers 2

4

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.

1
  • 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 Feb 15, 2010 at 18:08
1

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.

3
  • 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? Feb 15, 2010 at 10:58
  • 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. Feb 15, 2010 at 15:25
  • 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. Feb 15, 2010 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.