简体   繁体   English

Searchbar搜索数组项并将其显示在tableview上?

[英]Searchbar to search array items and displays them on a tableview?

I want to build an app that shows a empty tableview. 我想构建一个显示空表视图的应用程序。 Then users can write a text on a searchbar and when they click on Search button the tableview will be written with array items founded. 然后,用户可以在搜索栏上写文本,当他们单击“搜索”按钮时,将使用建立的数组项来编写表格视图。

I only need to search when user click SearchButton. 我只需要在用户单击“搜索按钮”时进行搜索。 How can I do this? 我怎样才能做到这一点? What methods do I have to use? 我必须使用什么方法?

I've tried with this method, but it doesn't works. 我已经尝试过这种方法,但是它不起作用。

- (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar {

    NSInteger nVideos = [appDelegate.allVideos count];

    NSLog(@"number of videos: %i", nVideos);

Do you update your datasource that associates with tableView? 您是否更新与tableView关联的数据源? As far as i can see, once user click search button with some search term, you should update your array that relates to tableView and reload it. 据我所知,一旦用户单击带有某些搜索词的搜索按钮,就应该更新与tableView相关的数组并重新加载它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM