开发者

checking which UITextField is triggering textFieldShouldBeginEditing call

开发者 https://www.devze.com 2023-01-08 11:44 出处:网络
What\'s the best way to determine which UITextField triggers the method -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField (开发者_Python百科or any of the other UITextFieldDelegate methods)?I

What's the best way to determine which UITextField triggers the method -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField (开发者_Python百科or any of the other UITextFieldDelegate methods)? I've seen code like this before:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    if (textField == textFieldCode) {
        return YES;
    }
    return NO;
}

but this only works if I have textFieldCode as an ivar in my class, and in this case I'm just initializing a couple of UITextFields and putting them in a table, so I don't have references to them in the class.

I was thinking that I could use the hash function and store the hashes for each textField somewhere in the class, and then compare textField's hash to the desired hash in the method call, but that seems like kind of a hack.


Since you only have a couple of fields, you can assign unique numbers to the tag properties of each textfield to enable identification.


You can have an iVar of NSArray that will contain all the text fields. Then just enumerate through it to find out which text field sent the message

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号