gpt4 book ai didi

ios - UISearchController 方法没有被调用

转载 作者:行者123 更新时间:2023-12-01 17:05:57 28 4
gpt4 key购买 nike

我以编程方式创建了一个 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com