I have a UITableView and i wan't to add a UITextField on top of the table, but I dont want it to scroll when the table view is scrolled. I want the uitextfield to remain on top. I looked at some previous answer on these forums, but they all talk about a .xib file and I'am trying to do this with Xcode 4.3 and storyboards. If you could provide some basic code it would be appreciated :)

1 Answer
1

You can do this easily. The trick is that you need to start by using a UIViewController instead of a UITableViewController.

If you are using Storyboards, start by dragging a UIViewController onto the canvas. Then drag a UITextField onto the view controller and position it where you want it (i.e. at the top). Next drag a UITableView (NOT UITableViewController) onto your viewcontroller, and set the table view's frame to cover all of the view controller's view except for the part of the view a the top where your text field is (i.e. the part you don't want to scroll). Then drag a UITableViewCell from the objects palate onto your table view. In the properties inspector, set the table view cell's Identifier property to something unique ("MyCell" or whatever.)

After you've done this your storyboard scene should look something like this:

Next you'll need to set your tableview's delegate and datasource properties. Don't forget to do this. Do this by Ctrl-clicking on the table view and dragging from the delegate and the datasource to your view controller.

and then implement the required methods in your view controller's implementation .m file. At a minimum you'll need to implement tableView:numberOfRowsInSection: and cellForRowAtIndexPath:, and probably tableView:didSelectRowAtIndexPath: and possibly others.