我的应用程序有两个主视图,它们在方向变化时切换,在纵向模式下的 View 应该有一个导航栏(我的代码在一个单独的应用程序中进行了测试,该应用程序运行良好,所以我要么将其传输错误,按下了一些奇怪的选项,该选项会在运行时禁用该栏,或者系统与横向 View Controller 不兼容,该 Controller 未链接到导航 Controller )但事实并非如此。
P.S:标签将其值更改为按下的表格单元格上的字符串以及animal/mounth
显示导航栏的 Storyboard:
屏幕截图显示在损坏的项目中表格 View 上没有导航栏的模拟器:
----想发布这些链接,但没有足够的声誉点----
点击表格单元格的结果屏幕截图,左上角应有一个后退箭头
工作测试项目的屏幕截图(不包含设备横向时实例化的 View ),显示了上一个屏幕截图的样子
我还将展示我的应用程序委托(delegate)类,其中包含工作项目和损坏项目之间的主要区别:
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()
}
}
最佳答案
当应用程序以纵向位置加载时,我正在实例化纵向 View Controller ,该应用程序直接加载 View 而不是通过导航 Controller 加载 View ,因此阻止了导航栏的加载。所以我转到我的 Storyboard并为导航 Controller 提供了 StoryboardID“NavController”,然后我用“NavController”替换了AppDelegate中“PortraitViewController”的所有使用,这意味着导航 Controller 正在加载 TableView 而不是应用程序跳过和在启动时加载没有导航栏的表格 View 。
关于ios - Xcode 快速导航栏在模拟器运行时消失,但在 Storyboard 中则不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38172566/