Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - multiple text field search bar

Tags:

iphone

I'm implementing a location based keyword search. If anyone has seen Yelp's search bar, it is what i'm trying to do. Basically once the search bar is clicked i want to provide one text field input for the keyword and the other for location. What UI element would I subclass? How would I go about this?

like image 869
prostock Avatar asked Dec 04 '09 22:12

prostock


2 Answers

Yelp's implementation looks to be a custom view with two UITextField objects, with a translation and scale animation to make it appear to be zoomed in from the top. A table view is added to the hierarchy after the animation is finished. The keyboard is invoked by making one of the text fields first responder.

BTW - generally speaking, composing UI elements together is preferred to subclassing.

like image 147
James J Avatar answered Nov 08 '22 09:11

James J


I also did a similar app, quite a while ago.
What I did in my app was I followed these steps, (I am only giving a brief description not the code part):

Initial look:

  • I used search bar inserted into a navigation bar. (I did it programmatically in the viewDidLoad of my class).
  • In my xib file of this class, I placed a view at the top and into it placed two UITextFields one below the other. I made this view hidden and shifted its y coordinates by the height of the view so that they became -(viewHeight).

Functionality Part

  • As soon as the user touches the search bar placed into the navigation bar, I made it hidden, unhidden the view with the text fields and shifted the y coordinates until they became 0 again.

  • In the delegate methods of search bar, - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar I returned NO, did the animation part (mentioned in the previous step) before returning NO from this method.

  • I made my first text field the first responder so that the keyboard appears automatically.

  • Now, when I am done filling data in both the text fields I reversed the animations and put the data filled into the text fields to the search bar.

Hope this helps.

like image 24
Madhup Singh Yadav Avatar answered Nov 08 '22 09:11

Madhup Singh Yadav