iOS 8为快捷

时间:2015-07-31 11:09:24

标签: ios iphone swift ios8 keyboard

我是swift的初学者,我一直在使用这个dismissKeyboard()方法,但它不能用于键盘扩展。

@IBAction func donePressed (sender: UIButton) {

      dismissKeyboard()


    }

谁能告诉我为什么这不起作用?

感谢。

编辑:完整代码

导入UIKit

类KeyboardViewController: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()


}

}

3 个答案:

答案 0 :(得分:1)

尝试那样

self.dismissKeyboard()

答案 1 :(得分:1)

也许试试:

// Database connection
$dbhost = 'localhost';
$dbname = 'databaseName';
$dbuser = 'userName';
$dbpass = 'userPassword';
$db = new PDO('mysql:host='.$dbhost.';dbname='.$dbname.';charset=utf8', $dbuser, $dbpass);
$db->exec("set names utf8");
// Disable enumeration of prepared statements to instantiate "real" prepared statements
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
// to implement try{} catch{} use PDO:ERRMODE_EXCEPTION
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);

// New PDO Query
$userQuery = "SELECT * FROM  ibew_Members WHERE Card = :userid";
$userQueryExec = $db->prepare($userQuery);
$userQueryArray = array(":userid" => $userid);
// Execution and Error reporting
try {
    $userQueryExec->execute($userQueryArray);
    if ($userQueryExec->rowCount() != 0) { // we have results 
        $results = $userQueryExec->fetchAll(PDO::FETCH_ASSOC);                  
        foreach($results as $result) { 
            echo "Relevant Info: ".$result['fieldname'];
        }
    } else {
        echo "No results found in the database for this user<br>\n";
    }
}
catch (Exception $e) {
    echo "Unable to complete Transaction: ".$e."<br>\n";
}

答案 2 :(得分:0)

从屏幕上关闭自定义键盘。

快捷键:

self.dismissKeyboard()

Objective-C:

[self dismissKeyboard];

https://developer.apple.com/documentation/uikit/uiinputviewcontroller/1618196-dismisskeyboard?language=objc