【发布时间】:2014-10-10 19:10:12
【问题描述】:
我在 Storyboard 上创建了一个带有一个 UITextField 的自定义 UIViewController。在viewDidLoad,我将 UITextFIeld 设置为becomeFirstResponder,什么也没发生(没有弹出键盘)。
然后我尝试调用resignFirstResponder(),但它返回错误。接下来,我试图通过使用@Get the current first responder without using a private API 上的代码循环所有子视图来查找first responder 是谁。事实证明,没有一个子视图是第一响应者。
故事板中的我的 ViewController
我的代码
class BLTestViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var tf: UITextField
override func viewDidLoad() {
super.viewDidLoad()
tf.delegate = self
tf.becomeFirstResponder()
// Do any additional setup after loading the view.
}
}
就这么简单...为什么键盘没有出现!!!我做的一件事是自动布局,但我不确定这是否会影响键盘弹出。
【问题讨论】:
-
尝试让您的文本字段成为
viewWill/DidAppear:中的第一响应者。 -
两个都试过了,都不行。
-
快速想法,我认为您可能仍然在 viewDidAppear 等中调用它为时过早...只是为了测试您是否可以设置调用包含 tf.becomeFirstResponder() 的方法的按钮 --- 这种方式我们可以排除时间问题
-
@尤金。我认为你是对的,这似乎是 xCode 6 模拟器本身的问题!!!该死的苹果。
-
见[这个问题][1]。基本按Apple+K[1]:stackoverflow.com/questions/24420873/…
标签: ios swift storyboard uitextfield becomefirstresponder