2013-07-18 52 views
0

我在app.and一個UISearchBar我想在這個UISearchBarfour範圍吧,我已經從XIB文件中給出.say one , two , three and four,現在的問題是我有包含四個array S代表分隔值每個陣列..say array one,array two,array threearray four的UISearchBar範圍棒法

現在我想,當我上按範圍酒吧two只有array two值應搜索等壓範圍酒吧one只有array one值應搜索.. 搜索..

是否有範圍欄按鈕的任何方法可供搜索?

If(scope_bar==1){...}else

就像如果我搜索範圍酒吧one那麼將只顯示array one。是否有任何方法可用..我搜索了蘋果文檔,但無法得到

回答

0

你應該閱讀一些關於NSDictionary的教程。我已經在圖書搜索應用中實施了這種搜索,其中標題和作者同時被搜索到。

//每本書

NSDictionary * book = NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: 
title, @"TITLE", author, @"AUTHOR", nil]; 
[dataSource addObject:book]; 

後,在搜索方法,你可以根據自己的方便更改

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

[tableData removeAllObjects]; 

if(searchText != nil && ![searchText isEqualToString:@""]){ 

    for(NSDictionary * book in dataSource){ 
     NSString * title = [book objectForKey:@"TITLE"]; 
     NSString * author = [book objectForKey:@"AUTHOR"]; 

     NSRange titleRange = [[title lowercaseString] rangeOfString:[searchText lowercaseString]]; 
     NSRange authorRange = [[author lowercaseString] rangeOfString:[searchText lowercaseString]]; 

     if(titleRange.location != NSNotFound || authorRange.location != NSNotFound) 
      [tableData addObject:book]; 
     } 

} 

[tableView reloadData]; 
}