Ste*_*ann 1 iphone objective-c nsarray nspredicate ios
我有一个NSArray,我想用谓词过滤.这就是我所拥有的.
NSLog(@"text is %@",txtSearch.text);
NSPredicate *bPredicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] '%@'",txtSearch.text];
arrSearchedPlayers =
[arrPlayers filteredArrayUsingPredicate:bPredicate];
NSLog(@"array after searched is %@",arrSearchedPlayers);
Run Code Online (Sandbox Code Playgroud)
当我输入文本时,我的数组保持为空.但是当我尝试这个谓词时,
NSPredicate *bPredicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] 's'"];
Run Code Online (Sandbox Code Playgroud)
我得到了正确的结果.任何人都知道问题是什么?
亲切的问候
删除谓词中的额外引号
[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@",txtSearch.text];
Run Code Online (Sandbox Code Playgroud)