我有一个textView,在其中输入网址并按下按钮。有一项服务可以检测链接并显示链接信息,如图像,描述等,
我的问题是,我们有没有选择,如果不按一下按钮就可以自动调用该服务。
例如我正在输入" facebook.com"现在没有按下按钮我可以拨打我的网络服务
答案 0 :(得分:0)
如果您使用的是UITextField,请使用此操作来检测文本更改;
[textField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
这是方法:
-(void)textFieldDidChange :(UITextField *)aTextField{
NSLog( @"text changed: %@", aTextField.text);
//Call your web Service
}
对于UITextView实现其委托方法:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
//text is the new part that is added to textView
return YES;
}
注意:不要忘记添加代表。