我在IOS中很新,我正在使用UISearchDisplayController
进行搜索。如何搜索字典数组并显示在UITableview中?
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY SELF == %@", searchText];
NSArray *filtered = [self.arrProductList filteredArrayUsingPredicate:predicate];
NSLog(@"%@", filtered);
}
,这里是我的self.arrProductList是数组的数组即
({ ID = 1; description = "Coalesce Functioning on impatience T-Shirt"; pname = "Coalesce Functioning T-Shirt"; price = "299.00"; qty = 99; }, { ID = 2; description = "Eater Krylon Bombear Destroyed T-Shirt"; pname = "Girl's T-Shirt"; price = "499.00"; qty = 99; }, { ID = 3; description = "The Get-up Kids Band Camp Pullover Hoodie"; pname = "Band Camp T-Shirt"; price = "399.00"; qty = 99; })
我的问题是如何使用键 “PNAME”搜索?我的应用程序坠毁在
filteredArrayUsingPredicate:
arrProductList是字典的阵列;-) – vadian
这是字典 –
的阵列哎呀对不起。我会更新我的答案:)。 –