【问题标题】:Xcode swift navigation bar disappears when simulator runs, but not whilst in storyboardXcode 快速导航栏在模拟器运行时消失,但在情节提要中不会
【发布时间】:2016-07-03 17:31:27
【问题描述】:

我的应用程序有两个主视图,它们在方向更改时打开,在纵向模式下的视图应该有一个导航栏(我的代码在一个单独的应用程序中进行了测试,它运行良好,所以我要么把它转移错了,按下了一些奇怪的选项,在运行时禁用栏,或者系统与未链接到导航控制器的横向视图控制器不兼容)但它没有。

P.S:标签将其值更改为按下的表格单元格上的字符串,以及动物/山

显示导航栏的故事板:

在损坏的项目中显示没有导航栏的模拟器的屏幕截图:

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

点击表格单元格的结果屏幕截图,左上角应该有一个后退箭头

来自工作 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()
    }
}

【问题讨论】:

  • 该死的,马上解决这个问题。我会发布我的修复以帮助其他人。

标签: ios iphone xcode swift uinavigationcontroller


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多