0

次のようなオブジェクトの配列をフィルタリングしようとしています:

{
    "id": "0",
    "title": "Crucifix and sarcophagus of Ariberto da Intimiano",
    "categoryName": "COMMEMORATIVE MONUMENTS",
    "audioFile": "Crucifix-and-sarcophagus-of-Ariberto-da-Intimiano",
    "videoFile": null,
    "textFile": "Crucifix-and-sarcophagus-of-Ariberto-da-Intimiano",
    "image": "content/0/Crucifix-and-sarcophagus-of-Ariberto-da-Intimiano_flow.jpg",
    "numPictures": "1",
    "didascalie": ["dida 1", "dida 2", "dida 3"],
    "description": "Crucifix and sarcophagus of Ariberto da Intimiano",
    "link": ""
},
{
    "id": "1",
    "title": "The sundial of Duomo",
    "categoryName": "THE SUNDIAL",
    "audioFile": "The-sundial-of-Duomo",
    "videoFile": null,
    "textFile": "The-sundial-of-Duomo",
    "image": "content/1/The-sundial-of-Duomo_flow.jpg",
    "numPictures": "2",
    "didascalie": ["dida 1", "dida 2", "dida 3"],
    "description": "The sundial of Duomo",
    "link": ""
}


NSPredicate *key1Predicate = [NSPredicate predicateWithFormat:@"title == '%@'",_searchAZ.text];

    _ArtWorksTableResults = [[_ArtWorksTable filteredArrayUsingPredicate:key1Predicate] mutableCopy];

    NSLog(@"%i",_ArtWorksTableResults.count);

検索を実行すると、_ArtWorksTableResults.count常に0.

しかし、次のように検索バーのテキストを使用する代わりに述語を書くと:

NSPredicate *key1Predicate = [NSPredicate predicateWithFormat:@"title == 'The sundial of duomo'"];

    _ArtWorksTableResults = [[_ArtWorksTable filteredArrayUsingPredicate:key1Predicate] mutableCopy];

    NSLog(@"%i",_ArtWorksTableResults.count);

_ArtWorksTableResults.countは、その1通りです!

私は何を間違えましたか?

検索バーのテキストもログに記録しようとしましたが、すべて問題ありません。

コードに直接検索のキーを書いたらなぜ動くのか理解できません!

4

2 に答える 2

0

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Predicates/Articles/pCreating.html

余分な ' 記号は必要ありません。フォーマッタによって追加されます

最後に:

@"%K == '%@'"
This predicate checks whether the value of the key %K is equal to the string literal “%@“ (note the single quotes around %@). The key name %K is supplied at runtime as an argument to predicateWithFormat:.
于 2013-08-11T09:53:41.093 に答える
0

パラメータを指定するときは、述語の形式に引用符を含めないでください。

[NSPredicate predicateWithFormat:@"title == %@",_searchAZ.text];
于 2013-08-11T09:51:20.343 に答える