0

以編程方式添加了uisearch欄和uisearchbardisplaycontoller(NO XIB),並且搜索欄sorta顯示在表格標題中,但不起作用。UISearchBar在UTableViewHeader中無法正確顯示

如果SETACTIVE:YES,SETACTIVE:NO顯示控制器上出現得很好,是功能

任何想法,爲什麼這可能發生?

在此先感謝

searchBar = [[UISearchBar alloc] init]; 
[self setSearchBarDisplayController:[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]]; 
[[self searchBarDisplayController] setDelegate:self]; 
[[self searchBarDisplayController] setSearchResultsDataSource:self]; 

summaryTableView = [[[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 416.0) style:UITableViewStylePlain] autorelease]; 
[summaryTableView setDataSource:self]; 
[summaryTableView setDelegate:self]; 
[summaryTableView setBackgroundColor:[UIColor clearColor]]; 
[summaryTableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; 
[summaryTableView setRowHeight:[PayCell height]]; 

[summaryTableView setTableHeaderView:searchBar]; 

[self.view addSubview:summaryTableView]; 

[searchBarDisplayController setActive:YES]; 
[searchBarDisplayController setActive:NO]; 

回答

0

難道說你還沒有建立searchResultsDelegate的搜索顯示控制器?

self.searchDisplayController.searchResultsDelegate = self; 

Developer Site上提到了這一點。沒有看到更多的代碼,很難說,但沒有設定它可能是你的問題的根源。下面是摘錄:

searchResultsDelegate爲 在顯示搜索結果 表視圖的委託。

@property(nonatomic,assign) id searchResultsDelegate Discussion 默認爲零。

+0

謝謝,但設置searchResultsDelegate沒有做任何事情。代碼非常簡單...使用UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UISearchDisplayDelegate創建一個searchBarDisplayController,搜索欄和一個可用的視圖。表視圖的所有委託方法都已實現,並使用單行裝入表。搜索委託實現,但空只是返回默認值。在這一點上,我只是試圖讓searchbar正確顯示,而不必在searchBarDisplayController上調用setActive:YES setActive:NO。 – SteveG 2011-04-24 15:40:39