执行 segue 后,嵌入式导航栏在 iOS 7(小屏幕)上消失,但在 iOS 9(大屏幕)上消失
Embedded Navigation bar disappears on iOS 7 (small screen size) but not iOS 9 (larger screen) after performing segue
我有一个名为 showPage
的显示转场,从视图控制器到 table 视图控制器,我正在调用 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 设备上尝试时,导航栏消失了,所以我看不到标题或点击 'back'。 table 视图因此从屏幕的最顶部开始并运行到状态栏中。
我尝试将顶部栏从 inferred
更改为 Translucent Navigation Bar
并将 nagivationBarHidden
设置为 false
self.navigationController?.navigationBarHidden = false
但它仍然没有出现在 iOS 7.
我刚刚在 viewDidAppear()
中尝试 print(self.navigationController)
tableviewcontroller,在我的 iOS 7 设备上,它打印 nil
,但在我的 iOS 9 设备上,它显示控制器:Optional(<UINavigationController: 0x12504e600>)
!为什么它不存在于旧设备上?我已经看到如果你有模态转场,导航控制器将不存在,但我正在做一个正常的节目转场,我不明白为什么它应该在一个设备上工作而不是另一个设备。
为什么会发生这种情况,为什么只发生在 iOS 7(或更小尺寸的设备)上?
会不会是因为我使用的 iOS 9 设备屏幕更大? (它是 iPhone 6S)但 iOS 7 设备是 iPhone 4,屏幕较小。我该如何调试它以检查它是否与屏幕尺寸有关?但是,table 视图控制器中的 none 单元格在任一设备上都以任何方式被切断。
我的故事板(点击看大图):
有问题的 segue 是 'Scan' 视图控制器和选择扫描视图控制器之间的一个。
我认为问题出在你的 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
modally
。这意味着在新 viewController
之上没有 navigationBar
。我认为你的情况就是这样。
您也可以尝试删除并重新创建一个新的 segue。看到这个:
'Show' segue in Xcode 6 presents the viewcontroller as a modal in iOS 7
我有一个名为 showPage
的显示转场,从视图控制器到 table 视图控制器,我正在调用 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 设备上尝试时,导航栏消失了,所以我看不到标题或点击 'back'。 table 视图因此从屏幕的最顶部开始并运行到状态栏中。
我尝试将顶部栏从 inferred
更改为 Translucent Navigation Bar
并将 nagivationBarHidden
设置为 false
self.navigationController?.navigationBarHidden = false
但它仍然没有出现在 iOS 7.
我刚刚在 viewDidAppear()
中尝试 print(self.navigationController)
tableviewcontroller,在我的 iOS 7 设备上,它打印 nil
,但在我的 iOS 9 设备上,它显示控制器:Optional(<UINavigationController: 0x12504e600>)
!为什么它不存在于旧设备上?我已经看到如果你有模态转场,导航控制器将不存在,但我正在做一个正常的节目转场,我不明白为什么它应该在一个设备上工作而不是另一个设备。
为什么会发生这种情况,为什么只发生在 iOS 7(或更小尺寸的设备)上?
会不会是因为我使用的 iOS 9 设备屏幕更大? (它是 iPhone 6S)但 iOS 7 设备是 iPhone 4,屏幕较小。我该如何调试它以检查它是否与屏幕尺寸有关?但是,table 视图控制器中的 none 单元格在任一设备上都以任何方式被切断。
我的故事板(点击看大图):
有问题的 segue 是 'Scan' 视图控制器和选择扫描视图控制器之间的一个。
我认为问题出在你的 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
modally
。这意味着在新 viewController
之上没有 navigationBar
。我认为你的情况就是这样。
您也可以尝试删除并重新创建一个新的 segue。看到这个:
'Show' segue in Xcode 6 presents the viewcontroller as a modal in iOS 7