我的數組是模型對象的集合,其字段爲name,address,arrTags。 這裏arrTags是一個NSArray。使用NSPredicate過濾文本是字符串數組的過濾數據數組
我必須根據arrTags值過濾我的數組。
例如。我有像倫敦,巴黎,澳大利亞這樣的價值觀。
我想顯示的數組索引,具有myArray的倫敦,如果我鍵入字母L.
到目前爲止,我已經做了以下內容:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"arrTags contains[c] %@", searchText];
arr_searchResults =[[NSMutableArray alloc] initWithArray:[myArray filteredArrayUsingPredicate:predicate]];
[image_view reloadData];
這顯示只有當我鍵入倫敦陣列在我的搜索欄中。 但是我想顯示數組,如果我開始鍵入L。
在此先感謝。
嘗試使用'beginswith',而不是'contains'。 – 2015-02-05 17:26:18
@IanMacDonald沒有運氣! – user3804063 2015-02-05 17:32:04
@IanMacDonald,錯誤彈出說不能適用於它不是子字符串。 (因爲它是一個標籤數組),所以你可以建議我如何訪問數組索引像索引[0]或我必須枚舉使用塊.... – user3804063 2015-02-05 17:46:43