UISearchController,uisearchbar

來源:互聯網
上載者:User

UISearchController,uisearchbar

搜尋方塊UISearchController的使用(iOS8.0以後替代UISearchBar + UIS)

1.在iOS 8.0以上版本中, 我們可以使用UISearchController來非常方便地在UITableView中添加搜尋方塊. 而在之前版本中, 我們還是必須使用UISearchBar + UISearchDisplayController的組合方式.

2.在使用UISearchController前先定義以下屬性

 

//定義一個UISearchController@property (nonatomic,strong) UISearchController *searchController;//用來展示搜尋結果@property (nonatomic,strong) ResultViewController *resultVC;//用來接收searchController搜尋出來的結果@property (nonatomic,strong) NSMutableArray *searchArr;

//開闢空間,用來接受搜尋出來的結果 _searchArr = [[NSMutableArray alloc] init];//執行個體化searchController _searchController = [[UISearchController alloc] initWithSearchResultsController:_resultVC];//設定搜尋更新時調用的代理 _searchController.searchResultsUpdater = self;//設定搜尋方塊,自適應,否則搜尋方塊無法顯示 [_searchController.searchBar sizeToFit];//將搜尋方塊添加到tableView上 [_tableView addSubview:_searchController.searchBar];//以下屬性感覺設定跟沒設定沒啥差別//設定開始搜尋時背景顯示與否 _searchController.dimsBackgroundDuringPresentation = NO;//搜尋時,背景變暗色 _searchController.dimsBackgroundDuringPresentation = NO;//搜尋時,背景變模糊 _searchController.obscuresBackgroundDuringPresentation = NO;//隱藏導覽列 _searchController.hidesNavigationBarDuringPresentation = NO;

  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.