6

我想知道如何控制UISearchDisplayController使用的表格視圖。您無法覆蓋UISearchDisplayControllersearchResultsTableView屬性,因爲它是只讀屬性。如何控制UISearchDisplayController的searchResultsTableView?

我試圖覆蓋searchResultsTableView自定義UITableView。這只是一次,但只要你嘗試第二次搜索,真正的searchResultsTableView再次上。 (我的意思是,在searchBar中鍵入一些文字,您的自定義表格視圖在頂部並顯示搜索結果,之後按下取消按鈕。現在,如果您重複此操作,您的自定義表格將不會顯示,並且UISearchDisplayController的searchResultTableView將在最上面)。

當然,你可以嘗試沒有UISearchDisplayController,但我指望這個類的優點,我只想定製tableView

回答

2

您對UISearchDisplayController一個TableViewDataSource屬性,此數據源產生的UITableViewCell。實施UITableViewDataSource協議,你就會有過的tableView的方法中的自定義控制:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

6

您不能設置searchResultsTableView,但你可以在適當的委託方法操縱它:

-(void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView { 
    tableView.backgroundColor = self.tableView.backgroundColor; 
    tableView.separatorColor = self.tableView.separatorColor; 
     ... 
+2

謝謝費利克斯,我已經嘗試過這種成功,但是這不是我想做的事情。我真的很喜歡,如果我可以設置我自己的UITableView的子類。我不想只是操縱searchResultsTableView的屬性。 – burki 2010-02-03 16:35:23

+1

@burki你是否設法使用你的UITableView子類?我有同樣的問題。 – Adriana 2012-11-09 19:58:28

相關問題