最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

keyboard - UITextField not responding except initially when set as first responder in Objective-CSwift hybrid project with IQKey

programmeradmin3浏览0评论

in a hybrid Objective-C project IQKeyboardManager handles all of the keyboard stuff in the Objective-C view controllers.

I have now created a Swift VC. The objective-C version of IQKeyboardManager is exposed in the bridging header. The VC is in a Storyboard, the class is set to the Swift class and there are outlets from the UIElements including the textfield that seem to be active to the Swift File.

However, the UITextFields in the Swift VC are completely unresponsive to touch. If you set the UITextField as first responder in code, you can type into it. However, once you stop typing and tap somewhere else on the keyboard, you can no longer type anything further in the UITextField and it is again inactive.

I have checked and no other views are blocking the textFields. The ViewController conforms to the UITextFieldDelegate. The delegates are set in code in ViewDidLoad.

One possibility is that maybe IQKeyboardManager is interfering. (Apparently there is a swift version of IQKeyboardManager but it is much heavier so I have not tried to include it.) However, Other UI elements, a button and a barbuttonitem are also inactive.

What might be the issue with these UIElements all being inactive? Here is some of the code that might be relevant:

Swift file:

 @objcMembers class FotPasswordVC: UIViewController, UITextFieldDelegate, UIGestureRecognizerDelegate {
           
        @IBOutlet weak var userName: UITextField!
        @IBOutlet weak var emailAddress: UITextField!
       
        @IBAction func sendButtonPressed(_ sender: Any) {
         print("Send button was pressed")
        }
        
        @IBOutlet weak var sendButton: UIButton!
        
       
        
        @IBAction func cancelAndDismiss(_ sender: Any) {
        print("Close button pressed")
        self.dismiss(animated: true, completion: nil)
        }
      
    //MARK: - LIFE CYCLE
    public override func viewDidLoad() {
        super.viewDidLoad()
        sendButton.setTitle("Retrieve Password", for: .normal)
        userName.placeholder = "Username"
        emailAddress.placeholder = "Email address"
        userName.becomeFirstResponder()
        userName.isUserInteractionEnabled = true
        emailAddress.isUserInteractionEnabled = true
        userName.delegate = self //SET DELEGATE
        emailAddress.delegate = self //SET DELEGATE
        instructionsLabel.text = "Enter username and email"
        sendButton.isEnabled = true
        emailAddress.isEnabled = true
        userName.isEnabled = true  
    }

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论