如何获取用户当前所在的UITextField的属性名称作为字符串? [英] How could I get the property name of the current UITextField a user is in as a string?

查看:50
本文介绍了如何获取用户当前所在的UITextField的属性名称作为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方法:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string

在此之前,为了找到我所在的当前文本字段,我能够编写如下内容:

Before, in order to find the current text field I was in, I was able to write something like this:

if (textField == self.textPlaceID)
{
    //Do something
}

有没有办法将我的textField的名称捕获为字符串?我不要求接受用户在textField中键入的内容,我希望能够获取if的属性名称.我需要它然后将其与其他字符串连接起来.我正在努力进行动态方法调用.

Is there a way to grab the name of my textField as a string? I am not asking to take what the user has typed in that textField, I'd like to be able to just get the property name of if. I need it to then concatenate it with some other strings. I am working on making a dynamic method call.

推荐答案

为每个textField(例如1,2,3 ....)预先分配唯一标签,对于textField标签避免使用0

Primarily assign unique tags to each of the textFields (eg 1,2,3.....) avoid 0 for a textField tag

-(void)viewDidLoad{
NSDictionary *dictionary ; //declare it in .h interface

dictionary =  [NSDictionary dictionaryWithObjectsAndKeys:@"textPlaceID",[NSNumber numberWithInt:1], @"textPlaceID2",[NSNumber numberWithInt:2],nil]; // add textField as object and tag as keys
}

更多..

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string{

NSString *textFieldPropertyName = [dictionary objectForKey:[NSNumber numberWithInt:textField.tag]];

}

这篇关于如何获取用户当前所在的UITextField的属性名称作为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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