0
如何搜索時,我有這種類型的陣列 這裏的是陣列在數組對象IOS NSPredicate搜索
@interface Recipe : NSObject
@property (nonatomic, strong) NSString* recipeName;
@property (nonatomic, strong) NSString* recipeId;
@property (nonatomic, retain) NSString* rcpDescription;
@property (nonatomic, retain) NSString* servingSize;
@property (nonatomic, retain) NSString* totalCalories;
在這裏,我在tableview中設置RecipeName中從陣列的數據的一個對象
Recipe* aRecipe = [recipeAry objectAtIndex:indexPath.row];
cell.lbl_name = aRecipe.recipeName
但問題是當我使用NSPredicate無法在這裏搜索是我的代碼請給我解決方案
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.recipeName= %@", searchText];
// SELF.shipBuilder LIKE[cd] %@
self.searchData = [recipeAry filteredArrayUsingPredicate:predicate];
NSLog(@"%@",self.searchData);
什麼'searchText'的價值?你試圖找到什麼價值?你在尋找'CONTAINS [c]'而不是? – Larme
我想搜索recipeName,但是當我nslog我的數組顯示 like this and search data is null –
SPredicate * predicate = [NSPredicate predicateWithFormat:@「SELF.recipeName CONTAINS [cd]%@」,searchText]; –