如何在多个UITextfields中使用UITextfield的文本? [英] How to use UITextfield's text in multiple UITextfields?

查看:111
本文介绍了如何在多个UITextfields中使用UITextfield的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UITextfield输入信息。我有几个UITextfields需要等于输入UITextfield。我正在使用这段代码:

I'm using a UITextfield to input information. I have several UITextfields that need to equal the input UITextfield. I'm using this bit of code:

       tex34.text = tex33.text;

如何扩展代码以处理多个文本字段?

How do I expand the code to handle multiple textfields?

推荐答案

没有广播的想法可以让你用一个语句设置它们。您只需拥有与文本字段一样多的作业。如果你有十亿个,你可以写一些Perl来输出代码。

There's no 'broadcast' idea that will allow you to set them all with one statement. You'll just have to have as many assignments as you have text fields. If you have a billion of them, you could write some Perl to output the code.

例如

tex34.text = text33.text;
tex35.text = text33.text;
tex36.text = text33.text;
tex37.text = text33.text;

如果您处于紧密循环中,可以使用临时字符串保存一些属性读取调用:

If you're in a tight loop, you can save some property read invocations using a temporary string:

const NSString *text = tex33.text;
tex34.text = text;
tex35.text = text;
//etc

如果真的有很多它们(不太可能),您可以将文本字段变量名称构建为NSStrings并使用键值编码来更新其文本属性:

If you really have a lot of them (unlikely), you can build the text field variable names as NSStrings and use key-value-coding to update their text property:

const NSString *text = tex33.text;

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

for (int i = 34; i < 1653; i++) {
   const NSString *key = [NSString stringWithFormat:@"tex%d.text", i];
   [self setValue:text forKey:key];
   if (i % 100 == 0) [pool drain];
}

[pool release];

这种方法要求您每个 texXX 设置为属性...

This approach will require that you have each texXX set up as a property...

这篇关于如何在多个UITextfields中使用UITextfield的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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