iOS UISearchDisplayController學習筆記,uisearchcontroller

來源:互聯網
上載者:User

iOS UISearchDisplayController學習筆記,uisearchcontroller

UISearchDisplayController和UISearchBar一起使用用來管理UISearchBar和搜尋結果的展示。UISearchDisplayController提供了顯示搜尋結果的tableview來覆蓋原控制器的視圖;

使用UISearchDisplayController需要:

  • 提供搜尋結果table的資料的來源-searchResultsDataSource
  • 搜尋結果table的代理 SearchResultsDelegate
  • UISearchDisplayController控制器的代理delegate ,相應搜尋事件的開始結束和顯示隱藏介面;(這個代理知道搜尋字串的改變和搜尋範圍,所以結果table能夠(自動)重新匯入)
  • searchBar的代理(關於UISearchBar代理上篇文章已經說明)

通常是在在uitableview中初始化UISearchDisplayController來展示一個列表;

searchController = [[UISearchDisplayController alloc]                         initWithSearchBar:searchBar contentsController:self];searchController.delegate = self;searchController.searchResultsDataSource = self;searchController.searchResultsDelegate = self;

在tabelview代理方法中需要判斷是哪一個table(UITableViewController中有self.tableView  UISearchDisplayController中有.searchResultsTableView)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {     if (tableView == self.tableView) {        return ...;    }    // If necessary (if self is the data source for other table views),    // check whether tableView is searchController.searchResultsTableView.    return ...;}
一個UIViewController和一個UISearchBar只有一個UISearchDisplayController;


你能夠在ios7 之後,在navigationbar中使用SearchDisplayController,通過配置UISearchDisplayController中得displaysSearchBarInNavigationBar和 navigationItem屬性;


相關的屬性和方法

@property(nonatomic, getter=isActive) BOOL active

展現(是否隱藏)狀態,預設值是NO,直接設定沒有動畫,用setActive:animated: 設定會有動畫

@property(nonatomic, assign) id<UISearchDisplayDelegate> delegate

代理

@property(nonatomic, assign) BOOL displaysSearchBarInNavigationBar

指定navigationbar中包含一個searchBar

@property(nonatomic, readonly) UINavigationItem *navigationItem

唯讀屬性 代表在navigation controller的navigationbar中的searchdisplaycontroller;

@property(nonatomic, readonly) UISearchBar *searchBar

UISearchDisplayController中的UISearchBar;

@property(nonatomic, readonly) UIViewController *searchContentsController

這個屬性管理著搜尋出的內容

@property(nonatomic, assign) id<UITableViewDataSource> searchResultsDataSource

展示搜尋結果的資料來源

@property(nonatomic, assign) id<UITableViewDelegate> searchResultsDelegate

搜尋結果展示的table的代理

@property(nonatomic, readonly) UITableView *searchResultsTableView

搜尋結果展示的table

@property(nonatomic, copy) NSString *searchResultsTitle

搜尋結果視圖的標題

- (id)initWithSearchBar:(UISearchBar *)searchBar contentsController:(UIViewController *)viewController

初始化控制器 指定關聯的search 和view controller

- (void)setActive:(BOOL)visible animated:(BOOL)animated

展現或者隱藏搜尋視圖

內容來自蘋果文檔



ios學習筆記哪兒有?自學ios開發合適?

不見得進培訓機構就是能學出來的,不見得交了錢就一定學出來,不過就看你本人有沒有自製能力了。
iOS的應用軟體是Android的1.4倍,而系統開發人員卻是Android的0.38倍,由此可見iOS行業的人才缺口是相當大的。也正因為如此,市場對於Objective-C和C++開發人員的需求極為迫切,使得這兩個職業在就業趨勢上呈相當利好的狀態,最終促使iOS行業大步跨入了朝陽行業。在現下這種供不應求的市場環境中,也促使iOS人才的薪資的上漲幅度要遠高於Android。

未來的10年是移動互連網的時代,這個結論已經成為業界的共識。
1:部署iOS應用是企業戰略必選項
2:大型企業的介入會加劇iOS人才的匱乏
3:iOS領域拒絕代碼工人,所謂的高手不僅精通技術,還要瞭解使用者,瞭解市場,瞭解設計,iOS領域偏向複合型人才和創新型人才
 
iOS開發 UISearchDisplayController 搜尋出來3個或者5個的時滾動tableview該滾動都不對

不太明白你所說的意思,你是要不滾動呢? 還是滾動的時候資料不對了?
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.