简体   繁体   English

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

[英]Embedded Navigation bar disappears on iOS 7 (small screen size) but not iOS 9 (larger screen) after performing segue

I have a show segue called showPage from a view controller to a table view controller and am calling performSegueWithIdentifier() to get it to show after clicking OK on a button in an alert: 我有一个名为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)
    }
}

This all works perfectly on my iOS 9 device, but when I try it on an iOS 7 device, the navigation bar disappears, so I can't see the title or click 'back'. 这一切都在我的iOS 9设备上完美运行,但是当我在iOS 7设备上试用时,导航栏消失了,所以我看不到标题或点击“返回”。 The table view therefore starts at the very top of the screen and runs into the status bar. 因此,表格视图从屏幕的最顶部开始,并进入状态栏。

I have tried changing the top bar from inferred to Translucent Navigation Bar and set nagivationBarHidden to false 我尝试将顶部栏从inferred更改为Translucent Navigation Bar并将nagivationBarHidden设置为false

    self.navigationController?.navigationBarHidden = false

but it still doesn't appear on iOS 7. 但它仍然没有出现在iOS 7上。

I just tried print(self.navigationController) in viewDidAppear() for the tableviewcontroller, and on my iOS 7 device, it prints nil , but on my iOS 9 device, it shows the controller: Optional(<UINavigationController: 0x12504e600>) ! 我只是在tableviewcontroller的viewDidAppear()尝试print(self.navigationController) ,在我的iOS 7设备上,它打印nil ,但是在我的iOS 9设备上,它显示了控制器: Optional(<UINavigationController: 0x12504e600>) Why does it not exist on the older device? 为什么它不存在于旧设备上? I've seen that the navigation controller won't exist if you have a modal segue, but I'm doing a normal show segue, and I can't understand why it should work on one device but not the other. 我已经看到如果你有一个模态segue导航控制器将不存在,但我正在做一个正常的show segue,我无法理解为什么它应该在一个设备上工作但不能在另一个设备上工作。

Why does this happen, and why only on iOS 7 (or a smaller size device)? 为什么会发生这种情况,为什么只在iOS 7(或更小尺寸的设备)上呢?

Could this be because the iOS 9 device I'm using has a larger screen? 这可能是因为我使用的iOS 9设备有更大的屏幕吗? (It's an iPhone 6S) but the iOS 7 device is an iPhone 4, which has a smaller screen. (这是iPhone 6S)但iOS 7设备是iPhone 4,它有一个较小的屏幕。 How do I go about debugging this to check whether it is a matter of screen size? 我该如何调试这个以检查它是否是屏幕尺寸的问题? However, none of the cells in the table view controller the segue goes to are cut off in any way on either device. 但是,在任何一个设备上,segue所用的表视图控制器中的任何一个单元都不会以任何方式被切断。

My storyboard (click for bigger image): 我的故事板(点击查看大图):

在此输入图像描述

The problematic segue is the one between the 'Scan' view controller and the choose scan view controller. 有问题的segue是'Scan'视图控制器和选择扫描视图控制器之间的segue。

I think the problem is with your showSegue ( showPage ) 我认为问题在于你的showSegueshowPage

From apple developer 来自苹果开发者

Show (Push) 显示(推送)

This segue displays the new content using the showViewController:sender: method of the target view controller. 此segue使用目标视图控制器的showViewController:sender:方法显示新内容。 For most view controllers, this segue presents the new content modally over the source view controller. 对于大多数视图控制器,此segue在源视图控制器上以模态方式呈现新内容。 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. 例如,导航控制器将新视图控制器推送到其导航堆栈。

Make sure your first viewController is embedded into a UINavigationController in Storyboard . 确保您的第一个viewController嵌入到StoryboardUINavigationController中。 Make the navigationController initialViewController if your first viewController is the initialViewController . 使navigationController initialViewController如果你的第一个viewControllerinitialViewController Or else it could present the new viewController modally . 否则它可以以modally呈现新的viewController That means no navigationBar on top of the new viewController . 这意味着在新的viewController之上没有navigationBar I think this is happening in your case. 我认为这是在你的情况下发生的。

You can also try delete and recreate a new segue. 您也可以尝试删除并重新创建一个新的segue。 See this: 看到这个:
'Show' segue in Xcode 6 presents the viewcontroller as a modal in iOS 7 Xcode 6中的“显示”segue将视图控件呈现为iOS 7中的模态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM