Objective c 在多个数组中搜索数据

Objective c 在多个数组中搜索数据,objective-c,arrays,uitableview,uisearchbar,searchbar,Objective C,Arrays,Uitableview,Uisearchbar,Searchbar,我正在为我的UITableview做一个搜索栏 到目前为止,它在-(void)searchthroughdata中只过滤了一个数组,即self.Title。 但是我想让它通过两个数组过滤——self.Title和self.Description 我的.h文件: @property (nonatomic, strong) NSArray * Images; @property (nonatomic, strong) NSArray * Title; @property (nonatomic, st

我正在为我的UITableview做一个搜索栏

到目前为止,它在-(void)searchthroughdata中只过滤了一个数组,即self.Title。 但是我想让它通过两个数组过滤——self.Title和self.Description

我的.h文件:

@property (nonatomic, strong) NSArray * Images;
@property (nonatomic, strong) NSArray * Title;
@property (nonatomic, strong) NSArray * Description;
@property (nonatomic, strong) NSMutableArray *results;
@property (nonatomic, strong) IBOutlet UISearchBar *SearchBar;
我的.m文件:

-(void)searchThroughData {

self.results = nil;
NSPredicate *resultsPredicate = [NSPredicate predicateWithFormat:@"SELF contains [search] %@", self.SearchBar.text];



self.results = [[self.Title filteredArrayUsingPredicate:resultsPredicate] mutableCopy];

}



-(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

[self searchThroughData];

}


 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {

if (tableView == self.tableView) {
    return _Title.count;

} else {
    [self searchThroughData];
    return self.results.count;

}

// Return the number of rows in the section.
//return _Title.count;
}

如何使其也通过NSArray*描述进行过滤

最好的选择是不要有多个阵列。相反,使用您的

@property (nonatomic, strong) NSArray * Images;
@property (nonatomic, strong) NSArray * Title;
@property (nonatomic, strong) NSArray * Description;
(或一个字典)并有一个包含这些对象的数组(我在这里假设您的数据模型…)


现在,当你过滤的时候,你可以用OR来检查谓词中的每一项。

谢谢,我有一个想法,那就是类似的东西,但我是一个noob。如何使一个数组包含两个数组?我算出了!无论如何谢谢你!!