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

标签 ios swift uinavigationcontroller swift2

我有一个名为 showPage 的节目转场从 View Controller 到 TableView Controller ,我正在调用 performSegueWithIdentifier()在单击警报中的按钮上的“确定”后使其显示:

@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 设备上尝试时,导航栏消失了,所以我看不到标题或单击“返回”。因此,表格 View 从屏幕的最顶部开始,一直延伸到状态栏。

我尝试从 inferred 更改顶部栏至 Translucent Navigation Bar并设置 nagivationBarHidden假的

    self.navigationController?.navigationBarHidden = false

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

我刚试过 print(self.navigationController)viewDidAppear()对于 tableviewcontroller,在我的 iOS 7 设备上,它打印 nil ,但在我的 iOS 9 设备上,它显示 Controller :Optional(<UINavigationController: 0x12504e600>) !为什么它不存在于旧设备上?我已经看到,如果你有模态转场,导航 Controller 将不存在,但我正在做一个正常的节目转场,我不明白为什么它应该在一个设备上工作而不在另一个设备上工作。

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

这会不会是因为我使用的 iOS 9 设备有更大的屏幕? (它是 iPhone 6S)但 iOS 7 设备是 iPhone 4,屏幕较小。我该如何调试它以检查它是否与屏幕尺寸有关?但是,在任一设备上,segue 转到的 TableView Controller 中的任何单元格都不会以任何方式被切断。

我的 Storyboard(点击看大图):

enter image description here

有问题的转场是“扫描” View Controller 和选择扫描 View Controller 之间的转场。

最佳答案

我认为问题出在您的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 中。如果您的第一个 viewControllerinitialViewController,请将 navigationController initialViewController。或者它可以呈现新的 viewController 模态。这意味着新的 viewController 之上没有 navigationBar。我认为这发生在你的情况下。

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

关于ios - 执行 segue 后,嵌入式导航栏在 iOS 7(小屏幕)上消失,但在 iOS 9(大屏幕)上不消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41490778/

相关文章:

swift - Firebase 调用中下标的使用不明确

ios - UINavigationController inside UITabBarController inside UISplitViewController(仍然)以模态方式显示细节 Controller 而不是推送

ios - 如何在 didSelectRow 之后关闭 UISearchController?

ios - UIAlertController 中不同的 UIPickerView 委托(delegate)/数据源

ios - UIWebView 中 pdf 的可点击区域

ios - 如何在 Swift 中从 Appdelegate 调用 View Controller 中的方法?

ios - AVAudioEngine 在连接 AVAudioPlayerNode 输出时抛出异常

ios - 考虑到时区,如何按日期属性获取记录?

ios - 修改 UITabBarController 的“更多”选项卡中显示的选项卡导航栏上的“更多”按钮

ios - Apple 推送通知服务是否过时?