iPhone how to get UITextField's text while typing?

后端 未结 7 2056
别那么骄傲
别那么骄傲 2020-12-12 21:54

I\'m trying to show changes made to a UITextField on a separate UILabel. Is there a way to capture full text of the UITextField after

7条回答
  •  悲&欢浪女
    2020-12-12 22:07

    In Swift 3.0:

    Some of these solutions were one character behind, or for earlier versions of Swift and Obj-C. Here is what I am using for Swift 3.0

    In the class I declared a placeholder to store the text.

    var tempName = ""
    

    In ViewDidLoad I used:

    nameField.addTarget(self, action: #selector(typingName), for: .editingChanged)
    

    Then I made a function called:

       func typingName(textField:UITextField){
    
            if let typedText = textField.text {
                tempName = typedText
                print(tempName)
            }
        }
    

提交回复
热议问题