使用 UITextField '搜索'标签文本 [英] 'Search' label text with UITextField

查看:26
本文介绍了使用 UITextField '搜索'标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UILabel 和一个 UITextField.每次用户在字段中输入文本时,我都需要检查标签文本中是否存在文本字段文本(基本上我正在搜索标签文本).我正在使用

I've got a UILabel and a UITextField. Each time the user enters text in the field, I need to check weather the textfield text exists in the label's text (basically I'm searching the label's text) . I was using

NSRange range = [sentenceRequestLabel.text rangeOfString:resultString];
if (range.location == NSNotFound) {
    NSLog(@"string was found");
} else {
    NSLog(@"string was not found");
}

检查(resultString 是 textfield.text),但即使文本字段中的标签文本甚至不接近标签文本,NSLog 也会说找到字符串".有什么想法吗?

to check (resultString being the textfield.text), but even if the label text in the text field is not even close to the label's text NSLog says "string was found". Any ideas what's wrong?

推荐答案

if (range.location == NSNotFound) {
    NSLog(@"string was found");

表示如果未找到字符串,则打印它已找到".== 应该是 !=.

means "If string was not found, then print it was found". That == should be a !=.

这篇关于使用 UITextField '搜索'标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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