我正在尝试设置uitextfield的焦点。使用此代码
[_partNoTextField becomeFirstResponder];
当我运行代码时,键盘消失,文本字段不在焦点上。我需要它在运行我的IBAction checkpartno后专注于_partNoTextField。在文本字段我已设置在结束时退出以调用我的checkpartno ibaction,因此当用户点击返回时它会运行它。如何让焦点回到_partNoTextField?
答案 0 :(得分:2)
不要使用“退出后退出”选择器,而是将文本字段中的委托设置回控制器,然后:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
// i.e. run your IBAction when clicking on return key
//
// here I am assuming your checkparno action lives in the
// same object as your delegate
[self checkpartno: textField];
return NO; // returning NO means the keyboard stays up
}