我以编程方式创建了一个searchBar,并将其添加到导航栏平铺视图中。这是我的代码:
UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:self];
searchController.dimsBackgroundDuringPresentation = YES;
// Use the current view controller to update the search results.
searchController.searchResultsUpdater = self;
//Setting Style
searchController.searchBar.barStyle = UIBarStyleBlack;
searchController.searchBar.barTintColor = [UIColor colorWithRed:49.0/255.0 green:49.0/255.0 blue:61.0/255.0 alpha:1.0];
searchController.searchBar.backgroundImage = [UIImage imageNamed:@"BG"];
searchController.searchBar.placeholder = @"Search Artists, Songs, Albums etc.";
searchController.searchBar.keyboardAppearance = UIKeyboardAppearanceDark;
self.definesPresentationContext = YES;
self.navigationItem.titleView = searchController.searchBar;
searchController.delegate = self;
searchController.searchBar.delegate = self;
[searchResultsTableView reloadData];
-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
NSLog(@"Halp.jpg");
return YES;
}
上述方法以及所有其他方法均未被调用。我的标题如下所示:
<UISearchResultsUpdating, UITableViewDelegate, UISearchControllerDelegate, UISearchBarDelegate, UITableViewDataSource>
答案 0 :(得分:0)
问题可能与这一行有关:
searchController.searchBar.delegate = self;
我怀疑UISearchController将自己设置为UISearchBar的委托,所以自己设置会以某种方式搞砸。