【发布时间】:2013-06-11 22:45:31
【问题描述】:
我有一个非常特殊的要求。由于情况不同,没有教程或已经提出的问题对我有用。它很特别,因为我想在不重新编程所有代码的情况下增强现有应用程序。
我想以编程方式添加 UISearchbar。 搜索栏应该添加到 UITableView 中,该 UITableView 也是以编程方式添加的。
这一切都发生在一个普通的 UIViewController 中。
我当前的方法显示搜索栏,但它不在我的 UITableView 中搜索。 根本没有任何反应。
我做错了什么?
myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchBar.delegate = self;
myTableView.tableHeaderView = searchBar;
UISearchDisplayController *searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
searchController.delegate = self;
myTableView.dataSource = self;
myTableView.delegate = self;
[self.view addSubview:myTableView];
【问题讨论】:
标签: objective-c uitableview uisearchbar uisearchdisplaycontroller