navigationBar.addSubview(bar) } } } // MARK: UISearchBarDelegate extension NavigationSearchItemHelper : UISearchBarDelegate { func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
为了实现搜索需要声明委托 UISearchBarDelegate , UISearchDisplayDelegate,其中搜索主要使用的就是UISearchDisplayDelegate,具体代码实现过程 indexPath.row]]; } else{ [cell.textLabel setText:self.dataList[indexPath.row]]; } return cell;} UISearchBarDelegate UISearchResultsUpdating: @interface ViewController : UITableViewController<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate
imageLiteral(resourceName: "VoiceSearchStartBtn"), for: .bookmark, state: .normal) 监听语音按钮的点击 // MARK:- UISearchBarDelegate extension LXFContactViewController: UISearchBarDelegate { func searchBarBookmarkButtonClicked(_
school -> Bool in school.contains(text) } } } } // MARK: - UISearchBarDelegate extension ViewController: UISearchBarDelegate { // MARK: 点击搜索 func searchBarSearchButtonClicked
//.控件的委托,委托要遵从UISearchBarDelegate协议,默认是nil bar.delegate = self; ③代理要试实现的协议方法 1).输入编辑事件处理 – searchBar setPlaceholder: @"搜索城市中文/拼音/字母"]; [_searchVC.searchBar setDelegate: self]; } 4.1.3 委托处理 4.1.3.1 UISearchBarDelegate 委托处理 #pragma mark - UISearchBarDelegate 委托处理 - (void) searchBarTextDidBeginEditing: (UISearchBar*)searchBar
///在 .h 写代理 <UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate> ///结合UITableView 展示了UISearchBar
.m文件中代码如下 添加搜索控制器的各种协议 <UISearchBarDelegate,UISearchResultsUpdating,UIAlertViewDelegate> 创建两个实例和数据源
self.setPositionAdjustment(offset, for: .search) } } 当我们点击顶部的搜索框时,页面需要跳转到真正的搜索页面,所以我们需要实现 UISearchBarDelegate 代理函数: extension DiscoveryViewController: UISearchBarDelegate { // 点击跳转 func searchBarShouldBeginEditing 这里就需要来实现 UISearchResultsUpdating 和 UISearchBarDelegate 这俩个代理了,通过 UISearchBar 获取到输入值,然后在提供的数据源中查找,并 reload } } extension MusicSearchViewController: UISearchBarDelegate{ func searchBar(_ searchBar: UISearchBar
boldSystemFontOfSize:10] forKeyPath:@"_placeholderLabel.font"]; [self addSubview:searchBar]; #pragma mark - UISearchBarDelegate
interface ViewController () <CLLocationManagerDelegate, MKMapViewDelegate, WWWAnnotationViewDelegate, UISearchBarDelegate