How to use UITextfield's text in multiple UITextfields? [closed]

て烟熏妆下的殇ゞ 提交于 2019-12-16 18:04:23

问题


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?


回答1:


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.

e.g.

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

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];

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



来源:https://stackoverflow.com/questions/9507875/how-to-use-uitextfields-text-in-multiple-uitextfields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!