zoukankan      html  css  js  c++  java
  • UISearchController

    • 示例

    //  SearchViewController.m
    
    @interface WYSearchViewController ()<UISearchBarDelegate, UISearchResultsUpdating>
    
    @property(nonatomic, strong) UISearchController *searchVC;
    @property(nonatomic, strong) WYSearchResultTableViewController *resultVC;
    
    #pragma mark - UISearchBarDelegate
    
    - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
        return YES;
    }
    
    - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar{
        
        return YES;
    }
    
    - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
        searchBar.showsCancelButton = YES;
        for(UIView *view in  [[[searchBar subviews] objectAtIndex:0] subviews]) {
            if([view isKindOfClass:[NSClassFromString(@"UINavigationButton") class]]) {
                UIButton * cancel =(UIButton *)view;
                if (searchText.length) {
                    [cancel setTitle:@"搜索" forState:UIControlStateNormal];
                } else {
                    [cancel setTitle:@"取消" forState:UIControlStateNormal];
                }
            }
        }
        
    }
    
    - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
        [self.searchVC.searchBar resignFirstResponder];
    }   // 键盘
    
    - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
        [self.searchVC.searchBar resignFirstResponder];
    }
    
    #pragma mark - search result delegate
    
    - (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
        if (searchController.searchBar.text.length) {
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        } else {
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        }
        
        BaiduLocation *baiduSearch = [BaiduLocation sharedBaiduLocate];
        baiduSearch.poiBlock = ^(NSArray *poiArray){
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            self.historyArray = [poiArray mutableCopy];
            self.resultVC.historyArray = self.historyArray;
            [self.resultVC.tableView reloadData];
        };
        [baiduSearch startPOIsearch:self.searchVC.searchBar.text];
    }
    - (UISearchController *)searchVC {
        if (!_searchVC) {
            _searchVC = [[UISearchController alloc] initWithSearchResultsController:self.resultVC];
            _searchVC.searchResultsUpdater = self;
            _searchVC.dimsBackgroundDuringPresentation = NO;
            _searchVC.searchBar.placeholder = @"大家都在搜:齐来大厦";
            _searchVC.searchBar.delegate = self;
            _searchVC.searchBar.returnKeyType = UIReturnKeySearch;
        }
        return _searchVC;
    }

      

    searchResultViewController

    // SearchResultViewController.m
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        [self initUI];
    }
    
    - (void)initUI {
        self.tableView.backgroundColor = [UIColor colorWithRed:231.0/255 green:231.0/255 blue:231.0/255 alpha:1];
        self.tableView.tableFooterView = [[UIView alloc] init];
    }
    
    #pragma mark - Table view delegate
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return self.historyArray.count;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
        if (!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UITableViewCell"];
        }
        NSDictionary *poiDic = self.historyArray[indexPath.row];
        cell.textLabel.text = poiDic[@"keyword"];
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%@%@", poiDic[@"city"], poiDic[@"district"]];
        
        return cell;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"selectKeyword" object:nil userInfo:self.historyArray[indexPath.row]];
    }
    
    - (NSArray *)historyArray {
        if (_historyArray == nil) {
            _historyArray = [NSArray new];
        }
        return _historyArray;
    }
    

      

  • 相关阅读:
    如何加快建 index 索引 的时间
    RMAN 系列(一) RMAN 体系结构概述
    RMAN 系列(二) RMAN 设置和配置
    对 Oracle 备份与恢复 的补充说明
    Oracle 11g Alert log 文件位置的问题
    Oracle 索引的维护
    分区表 之 Interval分区 和 虚拟列 按星期分区表
    Oracle 小知识 总结(一)
    如何用 SQL Tuning Advisor (STA) 优化SQL语句
    使用 Tkprof 分析 ORACLE 跟踪文件
  • 原文地址:https://www.cnblogs.com/dzhs/p/5758891.html
Copyright © 2011-2022 走看看