我有一个名为 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(点击看大图):
有问题的转场是“扫描” View Controller 和选择扫描 View Controller 之间的转场。
最佳答案
我认为问题出在您的showSegue
(showPage
)
显示(推送)
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
关于ios - 执行 segue 后,嵌入式导航栏在 iOS 7(小屏幕)上消失,但在 iOS 9(大屏幕)上不消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41490778/