[swift]解雇与 uiTextView 键盘

标签: UITextView Swift
发布时间: 2015/6/16 3:23:24
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我确信这不是那么难,但是我有问题在如何解雇键盘上找到信息...使用 textview,不是一个文本字段的返回/熟键在这里是什么我一直到目前为止 (该作品与 textfield...)

感谢在前进非常感谢任何帮助!

//  PostTravelQuestion.swift

import UIKit

class PostTravelQuestion: UIViewController, UITextViewDelegate {


    @IBAction func closepostpage(sender: AnyObject) {
        dismissViewControllerAnimated(true, completion: nil)
    }


    @IBOutlet var postquestion: UITextView!


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        postquestion.delegate = self
    }

    self addDoneToolBarToKeyboard:self.textView


    /*func textViewShouldEndEditing(textView: UITextView) -> Bool {

        textView.resignFirstResponder()

        return true
    }*/

    /*override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        postquestion.resignFirstResponder()
        self.view.endEditing(true)
    }*/



    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    func textViewShouldReturn(textView: UITextView!) -> Bool {
        self.view.endEditing(true);
        return true;
    }
}

解决方法 1:

这对我的作品:

import UIKit

class ViewController: UIViewController, UITextViewDelegate {


    @IBOutlet weak var textView: UITextView!

    override func viewDidLoad() {
        super.viewDidLoad()

        textView.delegate = self
    }

    func textView(textView: UITextView!, shouldChangeTextInRange: NSRange, replacementText: NSString!) -> Bool {
        if(replacementText == "\n") {
            textView.resignFirstResponder()
            return false
        }
        return true
    }
}
官方微信
官方QQ群
31647020