未调用 UISearchController 方法
Posted
技术标签:
【中文标题】未调用 UISearchController 方法【英文标题】:UISearchController methods not being called 【发布时间】:2015-12-01 13:25:46 【问题描述】:我以编程方式创建了一个 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>
【问题讨论】:
什么也没做,仍然表现完全一样 【参考方案1】:问题大概和这行有关:
searchController.searchBar.delegate = self;
我怀疑 UISearchController 将自己设置为 UISearchBar 的委托,所以自己设置会在某种程度上搞砸。
【讨论】:
以上是关于未调用 UISearchController 方法的主要内容,如果未能解决你的问题,请参考以下文章
为啥我的 UISearchController 委托方法没有被调用?