简体   繁体   中英

call prepareforsegue after user finished editing uitextfield

How do i pass the value of the text from the UITextField into another view controller. Currently, when I override the func prepareForSegue() , it is being called before the user finished editing the textfield, so the value passed is always null.

You have a couple of ways to go about this:

  1. Directly access the text value of your TextField instead of your model, which sounds like it is updated after didFinishEditing
  2. Instead of updating your model only on didFinishEditing you can update it every time the text changes by implementing internal func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool , and getting the new value with let newString = (textField.text! as NSString).stringByReplacingCharactersInRange(range, withString: string)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM