【发布时间】:2014-08-07 08:50:45
【问题描述】:
我正在尝试使用我的UITextfeild.text 中的文本过滤/搜索NSArray
如果我尝试搜索匹配字符串,过滤器会起作用,但当我在文本字段中键入字母时,过滤后的数组总是为空。
NSArray *testArray = [NSArray arrayWithObjects:@"testmailone@test.com",@"a@test.com",@"b@testing.com",@"h@fgdfgd",@"helloMan@test.com", @"dfsdfsdfsdfsdfs@dsfdfs",nil];
NSPredicate *predicatedString = [NSPredicate predicateWithFormat:@"SELF == %@", self.addHungryPersonTF.text];
NSArray *resultsArrayString = [testArray filteredArrayUsingPredicate:predicatedString];
NSLog(@"resultsArrayString%@",resultsArrayString);
这将返回 null 但如果我更改字符串以匹配另一个设置的字符串,如下所示:
NSString *matches = [NSString stringWithFormat:@"testmailone@test.com"];
NSLog
resultsArrayString(
"testmailone@test.com"
)
然后它会在数组中填充匹配的字符串。
有人知道为什么它不会按字母搜索我的NSArray吗?当我输入它应该正确地检查数组?
【问题讨论】:
-
也许在你的谓词中尝试使用
LIKE而不是==。 -
您的示例代码甚至无法编译。请提供真实的代码和输出。
标签: ios ios7 nsarray nspredicate