Cha*_*har 2 iphone uitextfield
我想问一下如何在iphone UITextField中单击(触摸开始写入)来调用方法,就像我们单击UIButton并将方法放在"addTarget"中一样,对于UITextFields有什么办法吗?
Mat*_*uch 12
实施UITextFieldDelegate,做任何你想在做- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField或- (void)textFieldDidBeginEditing:(UITextField *)textField
如果要阻止文本字段的行为类似于文本字段,则应使用第一种方法.例如,如果要在模态视图中打开文本字段编辑器.如果您不想要此行为,则可以返回NO.
编辑:这是调用myMethod的代码:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[self myMethod];
return YES;
}
Run Code Online (Sandbox Code Playgroud)