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:
@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'. 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
self.navigationController?.navigationBarHidden = false
but it still doesn't appear on 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>)
! 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.
Why does this happen, and why only on iOS 7 (or a smaller size device)?
Could this be because the iOS 9 device I'm using has a larger screen? (It's an iPhone 6S) but the iOS 7 device is an iPhone 4, which has a smaller screen. 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.
My storyboard (click for bigger image):
The problematic segue is the one between the 'Scan' view controller and the choose scan view controller.