2016-07-03 79 views
0

我的应用程序有两个主视图,它们在方向更改时打开,纵向模式中的视图应该有一个导航栏(我的代码在单独的应用程序,完美的工作,所以我要么转错了,按了一些奇怪的选项,禁用运行时的酒吧,或系统不兼容的横向视图控制器,它没有链接到导航控制器),但它不。Xcode swift导航栏在模拟器运行时消失,但不在故事板中时

PS:标签改变它的值,以被按压使在表单元中的字符串,而动物/芒斯

故事板显示导航栏:无导航栏上
Storyboard showing navigation bars

屏幕截图显示模拟器在破损项目中的表格视图:
Screenshot showing simulator without navigation bar on the table view in the broken project

----想要发布这些链接但没有足够的声望点----

截图从轻敲一个表格单元格的结果,应具有在顶部上的返回箭头左

从工作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() 
    } 
} 
+0

该死的,马上修好。我会在未来发布我的修补程序以帮助其他人。 –

回答

0

我被实例化的端口Rait视图控制器,当应用程序加载在纵向位置,直接加载视图,而不是通过导航控制器加载它,因此停止从未被加载的导航栏。所以我去了我的故事板,并给导航控制器的故事板ID“NavController”,然后我用“NavController”替换AppDelegate中的“PortraitViewController”的所有用法,这意味着导航控制器正在加载表视图,而不是应用程序跳过,在启动时加载没有导航栏的表格视图。