小编VH2*_*H24的帖子

UItextView委托swift-未调用textViewDidBeginEditing

我已经看过与UITextView委托有关的其他主题,但是似乎找不到我的问题的出处。这是我的代码,但是当我修改自己的代码时UITextView,什么也没有发生,textViewDidBeginEditing也没有被调用。

import UIKit
var textView1 = UITextView()

class ViewController: UIViewController, UITextViewDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()

        textView1.delegate = self
        textView1 = UITextView(frame: CGRect(x:24,y: 100,width: 340,height: 290))
        textView1.textColor = UIColor.black
        textView1.backgroundColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.00)
        textView1.text = "textView 1"
        view.addSubview(textView1)
    }

    func textViewDidBeginEditing(_ textView: UITextView) {
        print("print1")
    }

    func textViewDidEndEditing(_ textView: UITextView) { 
        print("print2")
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用UITextField,但没有任何更改,仍然没有调用委托函数。

uitextview uikit ios swift

5
推荐指数
1
解决办法
8884
查看次数

标签 统计

ios ×1

swift ×1

uikit ×1

uitextview ×1