2011-03-31 58 views
2

有無論如何,我可以在nsmutable陣列上使用搜索欄。我有數據是這樣的:關於nsmutable陣列的iphonesdk搜索欄

[listOfItems addObject:[NSArray arrayWithObjects: 
    @"Pakistan", 
    @A country with lot of salt mines", 
    nil] 
]; 

I M對錶視圖中顯示巴基斯坦和當點擊它,我在它的信息繼續其他視圖與。

我看到搜索欄與數組和字典,但無法找到可變數組請幫助。 由於事先

+0

如果你找不到可變數組,那麼你如何在數組和字典的搜索欄中找到它?請確保你以更好的方式提出問題。即使我很困惑..你想要做什麼搜索或傳遞數組到另一個ViewController? – 2011-03-31 10:32:18

回答

2

有一個在搜索欄的委託方法,可以幫助你喜歡:

-(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

然後你可以使用謂詞來過濾數據

NSPredicate * predicate = [NSPredicate predicateWithFormat:@"(title CONTAINS[cd] %@), searchText]; 
self.displayedData = [NSMutableArray arrayWithArray:[self.allData filteredArrayUsingPredicate:predicate]]; 
2

的NSMutableArray從NSArray中繼承,所以一樣的。