iPhone how to get UITextField's text while typing?

后端 未结 7 2057
别那么骄傲
别那么骄傲 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条回答
  •  猫巷女王i
    2020-12-12 22:28

    In Swift 2.0+

     class CheckInViewController: UIViewController, UITextFieldDelegate {
    
     override func viewDidLoad() {
        super.viewDidLoad()
    
        yourTextField.delegate = self
    
     }
    
     func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -> Bool {
        var updatedTextString : NSString = textField.text as NSString
        updatedTextString = updatedTextString.stringByReplacingCharactersInRange(range, withString: string)
    
        self.methodYouWantToCallWithUpdatedString(updatedTextString)
        return true
     }
    
    }
    

    Hope it helps you swift pioneers

提交回复
热议问题