I need to get the text from textfield
when I click over the backspace.
For Example :
I have a phone textfield
. When I click on each key, there is a search happens and it works fine using " shouldChangeCharactersInRange
" delegate. Once I delete any character from any where in the textfield
I need to get the rest of textfield
text and need to search. How can I achieve this?
Register for the below notification, then you will get notified for any text change. Then in the textFieldDidChange: method you can examine the contents of the textField
[textField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
- (void)textFieldDidChange:(id)sender
{
// Handle change.
UITextField* txt = (UITextField*)sender;
NSLog(@"txt = %@",txt.text);
//Write code to search from array or anything else.
}
要使用shouldChangeCharactersInRange
委托方法从UITextField
获取搜索文本,可以使用:
NSString *searchText = [textField.text stringByReplacingCharactersInRange:range withString:string];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.