2011-02-03 120 views
3

的我有被包含在UINavigationController作爲根元素與UISearchDisplayController(和UISearchBar)一個UITableViewController。是否可以配置它,以便UISearchBar代替UINavigationBar?我不認爲隱藏導航欄會工作,下一個屏幕(推送)要求它是可見的(這將創建一個奇怪的動畫故障)。的UISearchBar到位的UINavigationController UINavigationBar的

我基本上去爲喜歡App Store的搜索標籤的屏幕。

我上傳它現在的樣子的樣本截圖:

Default Configuration Selected Configuration

回答

4

將自己指定爲UINavigationController的的委託,實施- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

然後可使用navigationController傳遞到隱藏導航欄。 [navigationController setNavigationBarHidden:YES animated:animated]

編輯:試想想它,這將是更好的動畫值傳遞到-setNavigationBarHidden:animated:爲好。代碼已更新。

1

我想你可以通過「navigationBarHidden」屬性設置爲true隱藏你的導航欄。

[navigationController setNavigationBarHidden:YES animated:NO]; 
+0

然後我遇到問題推動下一個視圖控制器時,(即,它不具有導航欄)。如果我嘗試重新啓用它,我會得到暫時空白的導航欄。 – 2011-02-04 19:51:51

1

在控制器的viewDidLoad方法你是推

[[self navigationController] setNavigationBarHidden:NO animated:YES]; 
+0

看起來像是同樣的問題。 – 2011-02-17 21:51:36

6

這裏是我的解決方案:
你不需要隱藏UINavigationBar的,相反,你可以在合併的UISearchBar到UINavigationBar的。

在YourClass.m文件:
1.添加一個UISearchBar屬性
2.添加的UISearchBar到NavigationItem在viewDidLoad中部。 代碼:

@interface YourClass() 
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar; 
@end 

@implementation YourClass 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Reveal cancel button in UISearchBar. 
    searchBar.showsCancelButton = YES; 

    // Add UISearchBar as titleView of the UINavigationBar. 
    self.navigationItem.titleView = searchBar; 
} 

最後,不要忘記編輯您的.xib文件。只需在UINavigationBar下面添加UISearchBar對象,並將UISearchBar的引用插座連接到文件的所有者。 祝你好運!

相關問題