2012-06-09 64 views
0

我发现这个网站上的教程:的UISearchBar搜索按钮

http://jduff.github.com/2010/03/01/building-a-searchview-with-uisearchbar-and-uitableview/ 

...但我坚持在这里:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { 
// You'll probably want to do this on another thread 
// SomeService is just a dummy class representing some 
// api that you are using to do the search 
NSArray *results = [SomeSerivece doSearch:searchBar.text]; 

[searchBar setShowsCancelButton:NO animated:YES]; 
[searchBar resignFirstResponder]; 
self.tableView.allowsSelection = YES; 
self.tableView.scrollEnabled = YES; 

[tableData removeAllObjects]; 
[tableData addObjectsFromArray:results]; 
[self.tableView reloadData]; 
} 

我不明白我必须写,而不是SomeService。它正在评论中,但我无法理解。我已经有一个数组与表视图的所有内容...所以??我需要做什么??

回答

1

它看起来像一些服务是实际上根据xyz标准搜索数组并返回结果的类。如果我没有记错的话,UISearchBar会自动为你做这件事 - 你使用的教程可能过时了。

我个人还没有使用它,但以下可能会更有帮助;它使用UISearchDisplayController,它为您处理搜索结果,而不是强制您手动执行。

http://ygamretuta.me/2011/08/10/ios-implementing-a-basic-search-uisearchdisplaycontroller-and-interface-builder/

如果你想用的第一个教程,你必须创建/找到一个搜索类别阵列上使用。

+0

不幸的是我无法让教程工作。不知道为什么! – Alessandro

+0

不知道如何帮助你,除非你有更多的信息。究竟是不是在工作呢? –