Tej*_*mbe 19 iphone ios ios7 ios8 ios8.1
我正在使用UITextField的方法becomeFirstResponder来显示键盘.这适用于iOS 7.但在iOS 8中,此方法不显示键盘.
UITextField *txtAddNew = [[UITextField alloc] initWithFrame:CGRectMake(10,10,240, 21)];
txtAddNew.font = [UIFont fontWithName:@"Helvetica" size:16];
txtAddNew.clearButtonMode = UITextFieldViewModeWhileEditing;
txtAddNew.returnKeyType = UIReturnKeyDone;
txtAddNew.delegate = self;
txtAddNew.autocorrectionType = UITextAutocorrectionTypeNo;
txtAddNew.tag = 15;
// Open keyboard
[txtAddNew becomeFirstResponder];
Run Code Online (Sandbox Code Playgroud)
在iOS 8中有什么办法吗?
tha*_*rai 46
尝试像下面一样调用becomeFirstResponder
[txtAddNew performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0];
Run Code Online (Sandbox Code Playgroud)
按照Apple,
如果当前响应者可以辞退第一响应者状态(canResignFirstResponder)并且新响应者可以成为第一响应者,则响应者对象仅成为第一响应者.
您可以调用此方法来创建响应者对象,例如查看第一响应者.但是,如果它是视图层次结构的一部分,则只应在该视图上调用它.如果视图的window属性包含UIWindow对象,则它已安装在视图层次结构中; 如果它返回nil,则视图将从任何层次结构中分离.
Jac*_*son 14
斯威夫特3
这是接受答案的快速3版本.为了让我上班,我还不得不加延迟.
txtAddNew.perform(
#selector(becomeFirstResponder),
with: nil,
afterDelay: 0.1
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18256 次 |
| 最近记录: |