0

I have a UISearchBar with UITextField, and when I input a letter to the UITextField in Chinese or Japanese, just like "w", I found that the keyboard will show a panel which let user to choice a chinese word, but before I choice a word, I found that the UITextField will show the letter “w”, and the UISearchBarDelegate method:

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

not be called, and I want to get the letter with UITextField before I clicking the OK button with keyboard or choicing the word with showing panel. How to do? Thank you very much!

beryllium
  • 29,669
  • 15
  • 106
  • 125

2 Answers2

0

textField.delegate = self;

You need to set delegate, then only delegate method will be get called. Try this once!!

Naveen Thunga
  • 3,675
  • 2
  • 24
  • 31
  • I had tried this, and before click ok to choice a word , the delegate method of tiexfield not called , and I think maybe use UITextInputDelegate, but how to use it ? – benson_0205 Nov 28 '11 at 07:30
  • Can you show how you are creating UITextField's object & setting delegate variable? – Naveen Thunga Nov 28 '11 at 09:16
  • Sorry , maybe I didn't explain my question clearly, and I have set the delegate of uitextfield in uisearchbar, and when I tap a letter with English keyword , I can get the letter by textfield delegate methods, and when I taped a letter with Chinese or Japanese keyword, I will choice a word to call the textfield delegate , but Now I want to get the letter in the textfield before I choicing the word . just like When I taped a letter "w", and click ok button to choice a chinese word , then show in textfield and call the textfield delegate methods , but I want to get the letter before click ok btn – benson_0205 Nov 28 '11 at 10:00
  • Because when I tap a letter with chinese or japanese keyword , I will send the letter to server quickly and didn't want to choice a word and then send to the server, thank you very much~~ – benson_0205 Nov 28 '11 at 10:05
0

Have you tried the method

- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

in the UISearchBarDelegate protocol?

Zoleas
  • 4,869
  • 1
  • 21
  • 33
  • Ok, Thank you very much! I can get the text before choicing a word by click OK button , and the text which taped in searchbar is :[searchBar.text stringByReplacingCharactersInRange:range withString:text] – benson_0205 Nov 29 '11 at 05:20