品牌新的编码;几个月来一直在宗教上利用stackoverflow;第一次提问;请温柔。使用for循环以编程方式创建多个UITextField
我正在尝试使用for循环以编程方式创建一系列UITextFields。这些字段应该有“pax1name”,“pax2name”,“pax3name”等名称。
我缺少的是如何获取字符串并将其作为textField的名称, textField每次执行for循环。
这是我的代码,但也许我正在做这个错误的方式?先谢谢你!
// 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谢谢!这一切都归功于我昨晚在Holiday Inn Express酒店住宿...... – wannabeacoder