我在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
這是字典 –
的陣列哎呀對不起。我會更新我的答案:)。 –