Frage

I have tried both ways below to place SearchBar on UITableView.

  1. TabBarController > UITableViewController(Put SearchBar)
  2. TabBarController > UIViewController > UITableViewController(Put SearchBar)

When I try the second way, then it doesn't work. (SearchBar cannot show on UITableViewController)

Can anyone tell me what happend?

Here is my xcode project file: http://www2.zshares.net/tg14vowqzvaw

War es hilfreich?

Lösung

the usual way to do this would be to put the saerch bar in the header-section of the uitableview its supposed to search. you can do this using the

-tableview: viewForHeaderInSection:

method from the UITableViewDelegate-Protocol. his works in both TableViewControllers and regular ViewControllers that just have a TableView on them. see the mail app on the iphone for an example of this. if you really NEED the search bar to be outside of the tableview, then you will have to use a regular view controller and just place the search bar in a view above/under the tableView. other than that, i dont know what to tell you. And what is a TabbedViewController? Do you mean TabBarController? What does that have to do with search bars? Im kinda lacking the time to go through your project, so if you rephrase the question, maybe i can give a better answer?

EDIT-----------------------------------------------------

tableviewcontrollers will do that to you. basically, they will allow ONE tableview to be inside them at a time. also, this tableview WILL ALWAYS fill out the entire space available. Now, there is an exception to this that you cam make use of: Elements like a NavigationBar or a TabBar are allowed alongside the tableview, since they are required for navigation. So if you can put your stuff in one of these, its entirely fine. This my seem counterintuitive, since when do i want just a naked tableview on my screen? the answer is: more often than not. Tableviews are HIGHLY customizable using the UITAbleVIewDelegate-Protocol specified here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDelegate Do yourself a favor and read that doc, i almost guarantee that you will save time in the long run. For Example: You know the contacts app on your iphone? If you go into the details of one specific contact, you will find a pertty sophisiticated presentation of the data, that will even go into editing mode if you tap edit. It has a header, multiple segments, and a footer. Surprise: ALL OF THAT is just a single tableview in a tableviewcontroller, customized via the protocol. Let me repeat: you are wasting your own time if you try to do it any other way. tableviewcontrollers exist for a reason. usem them

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top