【发布时间】:2015-10-23 01:09:47
【问题描述】:
我是 swift 的初学者,我一直在使用这个 dismissKeyboard() 方法,但它不适用于键盘扩展。
@IBAction func donePressed (sender: UIButton) {
dismissKeyboard()
}
谁能告诉我为什么这不起作用?
谢谢。
编辑:完整代码
导入 UIKit
类键盘视图控制器:UIInputViewController {
var keyboardView: UIView!
@IBOutlet var nextKeyboardButton: UIButton!
override func updateViewConstraints() {
super.updateViewConstraints()
// Add custom view sizing constraints here
}
override func viewDidLoad() {
super.viewDidLoad()
self.loadInterface()
}
func loadInterface() {
var keyboardNib = UINib(nibName: "KeyboardView", bundle: nil)
self.keyboardView = keyboardNib.instantiateWithOwner(self, options: nil)[0] as UIView
view.addSubview(self.keyboardView)
view.backgroundColor = self.keyboardView.backgroundColor
self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside)
self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated
}
override func textWillChange(textInput: UITextInput) {
// The app is about to change the document's contents. Perform any preparation here.
}
override func textDidChange(textInput: UITextInput) {
// The app has just changed the document's contents, the document context has been updated.
}
@IBAction func buttonPressed (sender: UIButton) {
let title = sender.titleForState(.Normal)
var proxy = textDocumentProxy as UITextDocumentProxy
proxy.insertText(title!)
}
@IBAction func spacePressed (sender: UIButton) {
var proxy = textDocumentProxy as UITextDocumentProxy
proxy.insertText(" ")
}
@IBAction func deletePressed (sender: UIButton) {
var proxy = textDocumentProxy as UITextDocumentProxy
proxy.deleteBackward()
}
@IBAction func donePressed (sender: UIButton) {
resignFirstResponder()
}
}
【问题讨论】:
-
resignFirstResponder() 调用此方法而不是 dismissKeyboard() 但您需要像这样使用 textFieldDemo.resignFirstResponder() 调用...。您的 textField 实例在哪里.....跨度>
-
没有文本字段,它只是 iphone 的自定义键盘
-
好的,你只需调用 resignFirstResponder() 并告诉我
-
我尝试在 safari 和日历中使用它
-
没用,resignFirstResponder()
标签: ios iphone swift ios8 keyboard