views:

113

answers:

2

hi guys

I am developing an app which has a text field box. so when i am entering text, it should search the database and give me suggestions just like google search. like if i have entered letter 'a', it should have a box like thing below text field with all names starting with letter 'a'. then if i have entered letter 'b', it should resize the box and give names that start with 'ab' and so on.

I was planning to use a table view below the text field which reloads itself as and when new thing is entered into text field. but i dont know how to resize the table view depending on number of suggestions. So is there any other ui element which suits this kind of situations?

Also how do i detect a new alphabet or number entered into text field so that i can filter out suggestions like is there any such notification? what i mean to say is say i entered letter 'a' so now the string value of text field is 'a' and now i entered say 'b'. so now the string value changed to 'ab'. how do i detect this? i think textDidChange notification will do this for me.

Thanks

+1  A: 

You can use an NSComboBox for auto-completing lists like you describe. NSComboBox is a subclass of NSControl so you can use the -controlTextDidChange: delegate method to detect changes in the text that the user types. Make sure you set the control to "continuous" in Interface Builder or call [comboBox setContinuous:YES].

Rob Keniger
Thanks Rob. is there any way to hide the button in the end?I just want the text field without the button in the end.
King
A: 

If, for whatever reason, you find that a combo box is inappropriate for your situation, you can implement the list of completions as a child window of the control's window, with a headerless table view in it. Then you would programmatically resize that window as the number of possible completions changes.

Peter Hosey
Thanks Peter. This sounds more like what i want. Please can you explain me how to create a child window and display at the exact location(i.e just below the text field) and how to resize like depending on number of cells.
King
To get the correct location, get the view's frame, convert its origin to the content view's co-ordinate space, and convert that to screen space. That will be the top-left of your child window's frame. Then, create a window and add it as a child window of the view's window.
Peter Hosey