可以使用UITextFieldDelegate協議。更多詳細信息here。您必須在您的ViewController中實現方法- (void)textFieldDidEndEditing:(UITextFiled)textfield)*。
-(void) textFieldDidEndEditing:(UITextFiled*)textfield)
{
if (textField.text.length == 0) {
self.searchView.tipsView.hidden = NO;
} else {
self.searchView.tipsView.hidden = YES;
if (self.searchView.lySelectView.selectState == LYTabSelectOptionLeft) {
[self searchTagWithTagTitle:textField.text];
} else {
[self searchPeopleWithTagTitle:textField.text];
}
}
Asssign您的視圖控制器爲委託:
self.textField.delegate = self; //self is the ViewController.
後來編輯澄清後:
你要當用戶停止鍵入一個事件:你可以用一個模擬這個事件計時器。
@property (strong, nonatomic) NSTimer *timer;
....
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)strin {
if (self.timer != nil) {
[self.timer invalidate];
self.timer = nil;
}
self.timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(eventNeeded) userInfo:nil repeats:NO];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:self.timer forMode:NSDefaultRunLoopMode];
return YES;
}
-(void) eventNeeded{
NSLog(@"User has stopped typing.");
}
你想'textFieldDidEndEditing'嗎? – kai
我沒有明確表達,我不想要textfield末尾編輯,就像:你想輸入@「hotdog」,首先你快速輸入「hot」,過了一會兒,你繼續輸入「dog」 。我想得到你輸入「熱」的事件。我怎麼能? –