如何在搜索栏文本中显示?
How to make display in search bar text?
我在我的应用程序中创建了搜索栏。我使用 NSPredicate 但不起作用。
这是我的:
.m 文件:http://pastebin.com/CMsXpk4N
和 .h 文件:
#import <UIKit/UIKit.h>
@interface WordsViewController : UITableViewController <UISearchBarDelegate, UISearchControllerDelegate, UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *finalResultArray;
@property (nonatomic,strong) IBOutlet UISearchBar *searchBar;
@end
我的 searchBar 哪里有错误?
尝试以这种方式更改您的 NSPredicate
NSArray *filterArray= [self.finalResultArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%K contains[c] %@", @"expression", self.searchBar.text]];
predicateWithFormat
将自己在谓词格式字符串中应用 @"expression" key to each element of array, so you don't need to specify
self`。
此外,在谓词格式中,键的字符串占位符应为 %K,而不是 %@。
我在我的应用程序中创建了搜索栏。我使用 NSPredicate 但不起作用。 这是我的: .m 文件:http://pastebin.com/CMsXpk4N 和 .h 文件:
#import <UIKit/UIKit.h>
@interface WordsViewController : UITableViewController <UISearchBarDelegate, UISearchControllerDelegate, UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *finalResultArray;
@property (nonatomic,strong) IBOutlet UISearchBar *searchBar;
@end
我的 searchBar 哪里有错误?
尝试以这种方式更改您的 NSPredicate
NSArray *filterArray= [self.finalResultArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"%K contains[c] %@", @"expression", self.searchBar.text]];
predicateWithFormat
将自己在谓词格式字符串中应用 @"expression" key to each element of array, so you don't need to specify
self`。
此外,在谓词格式中,键的字符串占位符应为 %K,而不是 %@。