【发布时间】:2015-06-16 13:42:28
【问题描述】:
这是我在单击 UIButton 时以编程方式创建 UITextField 的编码。但要增强的是我想在创建 UITextField 时将焦点(并显示键盘)设置为新的 UITextField。
UITextField * txtComp=[[UITextField alloc]initWithFrame:CGRectMake(20,y, 450, 50)];
txtComp.borderStyle=UITextBorderStyleNone;
txtComp.delegate = self;
txtComp.tag=i+1;
txtComp.section=index;
txtComp.placeholder = @"New UITextField";
[txtComp becomeFirstResponder];
上面的编码工作是创建新的 UITextField,但即使设置了 becomeFirstResponder,也根本无法将焦点设置在新的 UITextField 上。
【问题讨论】:
-
我已经检查了你的代码在这里工作正常,我认为 txtcom.section=index 行中存在一些问题,只需将其删除并检查它
-
txtcom.section=index 用于分组,因此无法删除。在我身边,为什么键盘无法显示。
-
我已经使用了您的代码,只需删除该部分行,以便单击按钮后它会完美运行
-
你把 becomefirstresponder 放在哪里了?在 addSubview: 之后或 addSubview: 之前?
标签: objective-c xcode uitextfield