ios - UISearchController 方法没有被调用

标签 ios objective-c uitableview uisearchbar uisearchcontroller

我以编程方式创建了一个 searchBar 并将其添加到导航栏平铺 View 中。这是我的代码:

 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>

最佳答案

问题可能与此行有关:

searchController.searchBar.delegate = self;

我怀疑 UISearchController 将自己设置为 UISearchBar 的委托(delegate),因此自己设置它会以某种方式搞砸。

关于ios - UISearchController 方法没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34021572/

相关文章:

ios - iOS 5 中的自定义单元格问题

objective-c - 从 UIViewController 内部在 iOS objective-c 中绘制 4.000 个点或线

iOS 8 UIView 没有得到更新的问题

iphone - 学习 Obj-C 内存管理

ios - 在 didSelectRowAtIndexPath 中添加 subview

ios - 如何禁用 UITableViewcell iOS 中特定部分的 uitableViewCell 选择

ios - 使用 firebase 检索数据不返回任何内容

android - 移动应用程序上的 HTTPS 证书续订

ios - 如何阻止 UIScrollView 在 View 顶部时暂时向下滚动

ios - objective c 从 url 请求中解析 json