textFieldDidBeginEditing:用于多个文本字段 [英] textFieldDidBeginEditing: for more than one textfield

查看:206
本文介绍了textFieldDidBeginEditing:用于多个文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对iphone编程很新,在这里我遇到了一些问题。现在在我的应用程序中,我有两个文本字段,我想在第二个文本字段开始编辑时触发事件。现在我正在使用以下功能

I am fairly new to iphone programming and here I am facing some issues. Now in my application, I have two textfields and I want to fire an event while second textfield starts editing. now I am using following function

- (void)textFieldDidBeginEditing:(UITextField *)textField

但事情是在第一个文本字段开始编辑时被触发的事件。它不等待第二个文本字段。有没有办法可以将这个函数用于第二个文本字段,或者可能以某种方式知道并传递活动文本字段的值?

but the thing is the event is being fired when the first textfield starts editing. It does not wait for the second text field. Is there any way I can use this function for the second textfield or may be somehow could know and pass it the value of the active textfield?

我试着写一个名字函数中的文本字段而不是(UITextField *)textField,但结果仍然相同。

I tried writing the name of the textfield instead of (UITextField *)textField in the function but still the same result.

推荐答案

如果我是你,我会将第二个 textField 的标记(在Interface Builder中)设置为2或类似的东西。然后你可以这样做:

If I were you , I would set a tag (in Interface Builder) of the second textField to 2, or something similar. Then you can just do this:

-(void)textFieldDidBeginEditing:(UITextField *)textField {     
    if (textField.tag == 2) {
        //this is textfield 2, so call your method here
    }
}






编辑:请执行此操作以查看该方法是否被调用:


EDIT: Please do this to see if the method is even called:

-(void)textFieldDidBeginEditing:(UITextField *)textField {     
    NSLog(@"The method was called");
}

Swift 2.2

func textFieldDidBeginEditing(textField: UITextField) {
    if textField.tag == 2 {
        //this is textfield 2, so call your method here
    }
}

这篇关于textFieldDidBeginEditing:用于多个文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆