[英]call prepareforsegue after user finished editing uitextfield
How do i pass the value of the text from the UITextField into another view controller. 我如何将文本的值从UITextField传递到另一个视图控制器。 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. 当前,当我重写func prepareForSegue()
,它在用户完成编辑文本字段之前被调用,因此传递的值始终为null。
You have a couple of ways to go about this: 您有几种方法可以解决此问题:
text
value of your TextField
instead of your model, which sounds like it is updated after didFinishEditing
直接访问TextField
而不是模型的text
值,这听起来好像是在didFinishEditing
之后进行了更新 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)
代替仅在didFinishEditing
上更新模型,您可以在每次文本更改时通过实现internal func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool
并使用let newString = (textField.text! as NSString).stringByReplacingCharactersInRange(range, withString: string)
获取新值来更新模型let newString = (textField.text! as NSString).stringByReplacingCharactersInRange(range, withString: string)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.