执行segue后,嵌入式导航栏在iOS 7(小屏幕尺寸)上消失,但不会消失iOS 9(大屏幕)

我有一个名为showPage的show segue,从视图控制器到表视图控制器,我调用performSegueWithIdentifier()使其在警报按钮上单击OK后显示:

@IBAction func enterManuallyTap(sender: AnyObject) {
    var code : String!
    if #available(iOS 8.0, *) {
        let alert = UIAlertController(title: "Enter code", message: "Please enter code", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addTextFieldWithConfigurationHandler({ (input:UITextField) in
            input.placeholder = "your code"
        });
        alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
        alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (_) in
            barcode = alert.textFields!.first?.text
            self.performSegueWithIdentifier("showPage", sender: self)
        }))
        presentViewController(alert, animated: true, completion: nil)
    } else {
        let alert = UIAlertView(title: "Enter code", message: "Please enter code", delegate: self, cancelButtonTitle: "Cancel", otherButtonTitles: "OK")
        alert.alertViewStyle = UIAlertViewStyle.PlainTextInput
        alert.show()
    }
}

func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
    if buttonIndex == 1 {
        var code : String!
        code = alertView.textFieldAtIndex(0)?.text
        self.performSegueWithIdentifier("showPage", sender: self)
    }
}

这一切都在我的iOS 9设备上完美运行,但是当我在iOS 7设备上试用时,导航栏消失了,所以我看不到标题或点击“返回”.因此,表格视图从屏幕的最顶部开始,并进入状态栏.

我尝试将顶部栏从推断更改为半透明导航栏并将nagivationBarHidden设置为false

    self.navigationController?.navigationBarHidden = false

但它仍然没有出现在iOS 7上.

我只是在tableviewcontroller的viewDidAppear()中尝试打印(self.navigationController),在我的iOS 7设备上,它打印nil,但是在我的iOS 9设备上,它显示了控制器:可选(< UINavigationController:0x12504e600>)!为什么它不存在于旧设备上?我已经看到如果你有一个模态segue导航控制器将不存在,但我正在做一个正常的show segue,我无法理解为什么它应该在一个设备上工作但不能在另一个设备上工作.

为什么会发生这种情况,为什么只在iOS 7(或更小尺寸的设备)上呢?

这可能是因为我使用的iOS 9设备有更大的屏幕吗? (这是iPhone 6S)但iOS 7设备是iPhone 4,它有一个较小的屏幕.我该如何调试这个以检查它是否是屏幕尺寸的问题?但是,在任何一个设备上,segue所用的表视图控制器中的任何一个单元都不会以任何方式被切断.

我的故事板(点击查看大图):

《执行segue后,嵌入式导航栏在iOS 7(小屏幕尺寸)上消失,但不会消失iOS 9(大屏幕)》

有问题的segue是’Scan’视图控制器和选择扫描视图控制器之间的segue.

最佳答案 我认为问题在于你的showSegue(showPage)

From apple developer

显示(推送)

This segue displays the new content using the
showViewController:sender: method of the target view controller. For
most view controllers, this segue presents the new content modally
over the source view controller. Some view controllers specifically
override the method and use it to implement different behaviors. For
example, a navigation controller pushes the new view controller onto
its navigation stack.

确保您的第一个viewController嵌入到Storyboard中的UINavigationController中.如果您的第一个viewController是initialViewController,请使navigationController为initialViewController.否则它可以以模态方式呈现新的viewController.这意味着在新的viewController之上没有navigationBar.我认为这是在你的情况下发生的.

您也可以尝试删除并重新创建一个新的segue.看到这个:
‘Show’ segue in Xcode 6 presents the viewcontroller as a modal in iOS 7

点赞