【发布时间】:2011-07-11 14:07:42
【问题描述】:
全新的编码;几个月来一直在虔诚地使用stackoverflow;第一次提问;请温柔一点。
我正在尝试使用 for 循环以编程方式创建一系列 UITextField。字段应具有“pax1name”、“pax2name”、“pax3name”等名称。
我缺少的部分是如何获取一个字符串并将其设置为 textField 的名称,每次执行 for 循环时更改 textField 的名称。
这是我的代码,但也许我做错了?提前谢谢!
// set up the names textfields
for (int i = 0; i < 7; i++) {
NSString *fieldName = [[NSString alloc] initWithFormat:@"pax%iname", (i + 1)];
// I can't figure out what goes here to create a UITextField with the name of fieldName
textField = [[UITextField alloc] initWithFrame:CGRectMake(15, (15 + (i * 40)), 400, 40)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:15.0];
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[namesViewController addSubview: textField];
[fieldName release];
[textField release];
}
【问题讨论】:
-
+1 表示您的第一个 SO 问题完整、清晰且包含代码。干得好。
-
@DanRay 谢谢!这一切都归功于我昨晚住在智选假日酒店....
标签: objective-c xcode