我有一个非常特别的要求。由于情况不同,没有教程或已经提出的问题对我有用。它很特别,因为我想在不重新编程所有代码的情况下增强现有应用程序。
我想以编程方式添加一个 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];