![](/img/trans.png)
[英]SWIFT 5 - navigation bar disappears after calling “show” method for changing storyboard
[英]Xcode swift navigation bar disappears when simulator runs, but not whilst in storyboard
我的應用程序有兩個主要視圖,這些視圖均已打開方向更改,而在縱向模式下,該視圖上應有一個導航欄(我的代碼在單獨的應用程序中經過測試,該應用程序運行良好,因此我將其錯誤地傳輸了,按了一些奇怪的提示選項可在運行時禁用條形圖,或者系統與橫向視圖控制器不兼容,橫向視圖控制器未鏈接到導航控制器),但不兼容。
PS:標簽將其值更改為按下的表格單元格上的字符串以及動物/坐騎
顯示導航欄的情節提要:
屏幕截圖顯示了斷開的項目中表視圖上沒有導航欄的模擬器:
----想發布這些鏈接,但沒有足夠的信譽點----
點擊表格單元格的結果屏幕截圖,應該在左上方有一個后退箭頭
運行的testProject的屏幕截圖(其中不包含將設備定向為橫向時實例化的視圖),顯示了先前的屏幕截圖應該是什么樣子
我還將展示我的應用程序委托類,其中包含工作項目與損壞的項目之間的主要區別:
var window: UIWindow?
var storyboard:UIStoryboard!
var initialViewController:UIViewController!
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// Create rotation function and call it whenever the device is rotated
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(AppDelegate.rotated), name: UIDeviceOrientationDidChangeNotification, object: nil)
// Set default ViewController based on rotation
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
storyboard = UIStoryboard(name: "Main", bundle: nil)
// Declare InitialViewController as portrait to avoid NSInternalInconsistencyException
initialViewController = storyboard.instantiateViewControllerWithIdentifier("PortraitViewController")
// Declare initial view controller based on device orientation
if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)){
initialViewController = storyboard.instantiateViewControllerWithIdentifier("PortraitViewController")
} else if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation)){
initialViewController = storyboard.instantiateViewControllerWithIdentifier("LandscapeViewController")
}
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
return true
}
/// Called when the screen is rotated
func rotated()
{
// if device is landscape show LandscapeViewController
if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation))
{
initialViewController = storyboard.instantiateViewControllerWithIdentifier("LandscapeViewController")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
}
// if device is portrait show PortraitViewController
if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation))
{
initialViewController = storyboard.instantiateViewControllerWithIdentifier("PortraitViewController")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
}
}
當應用程序以縱向位置加載時,我正在實例化縱向視圖控制器,該應用程序直接加載視圖而不是通過導航控制器加載視圖,因此停止了導航欄的加載。 因此,我轉到情節提要,為導航控制器提供了情節提要ID“ NavController”,然后將AppDelegate中“ PortraitViewController”的所有用法替換為“ NavController”,這意味着導航控制器正在加載表格視圖,而不是應用程序跳過和在啟動時沒有導航欄的情況下加載表格視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.