我在UINavigationBar
上有UISegmentedControl
。該UIViewController
嵌入從故事情節進行UINavigationController
屏幕截圖中,見下圖:iOS9:在導航欄中隱藏SegmentedControl後不會出現標題
如果該設備是一個iPad
,我想隱藏UISegmentedControl
並顯示出self.title
代替。
在我viewDidLoad
,我有下面的代碼:
override func viewDidLoad() {
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
segmentedControlNavBar.hidden = true
self.title = "Navigation Title"
} else {
segmentedControlNavBar.hidden = false
navigationItem.prompt = "Navigation Title"
self.title = nil
}
}
Resul(從模擬器):
我也試過viewWillAppear
,但無濟於事。
如果我從Storyboard
中拿出UISegmentedControl
,UINavigationBar
標題顯示正常。
如何隱藏導航欄中的UISegmentedControl
並顯示標題?
編輯
override func viewDidLoad() {
super.viewDidLoad()
segmentedControlMain.hidden = true
navigationItem.prompt = nil
title = "Navigation Title"
let items = self.navigationController?.navigationBar.items
print(items?.first?.title)
}
日誌:可選( 「標題導航」)
我想它的存在,我該如何讓UINavigationBar的表現出來?
這些沒有工作:
self.navigationController?.view.setNeedsDisplay()
self.navigationController?.navigationBar.setNeedsDisplay()
請看看我的編輯 – user1107173
我想我們需要更多的信息來進行調試這件事,但如果「hidden = true」不起作用有時調用setter方法工作(不要問我爲什麼)[segmentedControlMain setHidden:YES]; 仔細檢查segmentedControlMain和視圖之間的連接,也可能會將segmentedControlMain的alpha設置更改爲0.0以使其透明 – MrJomp
分段控件已隱藏。但標題沒有出現。 – user1107173