パラメーターの種類を知らずに正確なアドバイスを伝えることは困難ですが、私が見る限り、4 つの変数 (おそらく NSStrings) が必要であり、ユーザーがパラメーターを変更するたびに、新しい変数を作成します。すべての変数を正しい形式で追加することにより、述語をフェッチします。それが私が一般的に見ている方法です。
アップデート
したがって、Market ボタンと Tag ボタンを使用すると、すべてが非常に明白になります。使用する必要がありますNSCompondPredicate
。述語の配列が必要になるので、プロパティを作成します。
@property (strong) NSMutableArray *subpredicates;
次に、ユーザーがボタンに触れるたびに、その絞り込み述語を追加または削除します。
- (void)tagButtonTouched:(UIButton *)button
{
if (thisTagIsNotYetSelected)
[subpredicates addObject:[NSPredicate predicateWithFormat:@"ANY tags.name == %@", button.titleLabel.text]];//or some other predicate based on that button title
else
[subpredicates removeObject:[NSPredicate predicateWithFormat:@"ANY tags.name == %@",button.titleLabel.text] ]];
}
同じことMarkets
- (void)marketButtonTouched:(UIButton *)button
{
if (thisMarketIsNotYetSelected)
[subpredicates addObject:[NSPredicate predicateWithFormat:@"ANY markets.name == %@", button.titleLabel.text]];//or some other predicate based on that button title
else
[subpredicates removeObject:[NSPredicate predicateWithFormat:@"ANY markets.name == %@",button.titleLabel.text] ]];
}
また、selected の値を保持NSPredicates
する2 つの変数を追加する必要があります。ユーザーがこれらのスイッチに触れると(なぜセグメント化されたコントロールではないのですか?)、それらの値を変更するだけです。NSString
FeedType
PhotoType
feedTypePredicate
photoTypePredicate
そして最後に、これらすべての述語を 1 つに結合して、フェッチを行う必要があります。
if(photoTypePredicate)
[subpredicates addObject:photoTypePredicate];
if(feedTypePredicate)
[subpredicates addObject:feedTypePredicate];
NSPredicate *finished = [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates];//Your final predicate