2011-04-15 70 views
1

貌似愚蠢的問題,但...:裏面的UISearchBar UINavigationController的

- (void)viewWillAppear:(BOOL)animated { 

[super viewWillAppear:animated]; 
self.bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 20.0, self.navigationController.view.bounds.size.width, HEADER_HEIGHT)]; 
mySearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:bar contentsController:self]; 
mySearchDisplayController.delegate = self; 
mySearchDisplayController.searchResultsDataSource = self; 
mySearchDisplayController.searchResultsDelegate = self; 
[self.navigationController.view addSubview:self.bar]; 

所有的行爲都工作正常,而我不要按取消或牆根的tableview。 之後,搜索欄關閉,我看到一個清晰的導航欄,沒有搜索欄。 我已更改爲viewDidload,但沒有任何更改。

開始打印前:

enter image description here

後:

enter image description here

+1

能不能介紹一下你所看到的行爲解釋一下? 'viewWillAppear'並不是真正的這種代碼的地方。 'viewDidLoad'更合適。 – 2011-04-15 01:08:27

回答

1

嘗試添加搜索欄作爲titleview的進行的導航欄。它可能工作。

請參閱本網站

http://iphonesdevsdk.blogspot.com/2011/04/custom-tableview.html

它可以幫助你

+0

它的工作,[[self.navigationController.navigationBar topItem] setTitleView:self.bar];但是當我嘗試在搜索欄中寫入內容時,搜索欄即將關閉,就像searchcontroller認爲搜索欄放在表格中,而不是在導航欄中。 – Alex 2011-04-15 07:37:38

+0

你可以把你的代碼與搜索欄的快照(搜索欄上去和關閉)。我可以看到發生了什麼問題。 – Anand 2011-04-15 11:31:06

+0

tnx,請看這裏,代碼沒有什麼添加只是明確的委託功能; – Alex 2011-04-15 13:48:34

相關問題