知道textField:shouldChangeCharactersInRange:replacementString中完整的已更改字符串: [英] Knowing the complete changed string in textField:shouldChangeCharactersInRange:replacementString:

查看:56
本文介绍了知道textField:shouldChangeCharactersInRange:replacementString中完整的已更改字符串:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚问了有关如何监控的问题更改为 UITextField 并收到以下响应:

I just asked a question about how to monitor changes to a UITextField and received this response :

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)replacementStr {
    // Enable "Next" if you like what's entered in the replacementStr
}

这可行,但是替换字符串不是整个字符串,而是它所添加的内容。如何获得整个字符串?我的目标是查看文本字段中的字符串是否为空白或等于某个数字(在不同情况下)。

This works, but the replacement string is not the whole string, just what it is adding. How can I get the whole string? My objective is to see if the string in the text field is blank or equal to a certain number (in different scenarios).

请注意,在这种情况下,文本字段的出口无效,因为在更改字段文本之前会调用此方法。

Please note that the outlet to the text field doesn't work in this case, because this method is being called before the text in the field changes.

推荐答案

NSString * proposedNewString = [[textField text] stringByReplacingCharactersInRange:range withString:replacementString];

这篇关于知道textField:shouldChangeCharactersInRange:replacementString中完整的已更改字符串:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆