Keeping UINavigationBar on top when programatically calling a segue - ios

I have an application that links to a view via a button (which is embedded inside a navigation controller)
Which all works fine! I hit the button and the view is presented using Segue Show Eg: Push. The view pops over and I see a UINavigationBar with my title and a button to dismiss.
My question is.. I need to programatically call this view again in my code, however, when I do this the view appears without any UINavigation. I assume it does this because it's no no longer embedded inside the UINavigationController?
Whats the best solution for this? Should I programatically create the UINavigationBarController? If so how would this look in swift?
Thank in advanced.
// Code below is triggered from an action (button) on UIAlertController.
// This loads up the "Scan Barcode view" without the UINavigationBar embedded.
let scannerViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ScannerViewController") as ScannerViewController
self.presentViewController(scannerViewController, animated: true, completion: nil)
When I set up the connection using interface builder from another button (located elsewhere) so show the same view. It works perfectly showing the "Scan Barcode" embedded inside the Navigation Controller.
When using interface builder to link (from the camera button) it works perfect.

Thanks to #kpsharp the solution was just to use
self.navigationController?.pushViewController(scannerViewController, animated: true)

Related

Bar item button not displayed at runtime but visible at design time in a modal view

I have being trying different things and looking around for a while without finding an answer to my problem. Maybe I'm doing something fundamentally wrong.
The sample application consists of:
A first view controller that displays a second view controller using a segue. This works fine.
A second view controller, in which I have simulated the display of a third view programmatically, which contains a bar item button (named "Done") that I would like to display.
The bar item button in the third view controller is not displayed at runtime but is displayed in IntefaceBuidler at design time.
This third view controller needs to be displayed modal.
What I'm doing wrong to display this bar item button?
A sample project illustrating the problem is available here.
Below a screen capture of the bar item button at design time:
Below a screen capture of the bar item button not showing at design time:
PS:
Please disregard the "Unknown class ThirdViewControlller in Interface Builder file.", since the ThirdViewController is displayed fine at runtime. Also, the "Done" button in the middle of the view works fine.
In SecondViewController you need to push the third onto the navigation controller stack like so:
self.navigationController?.pushViewController(thirdViewController, animated: true)
You are currently presenting it as a modal. Also, you've unnecessarily added a second UINavigationController to your storyboard (for the third view controller)
If you want to present a modal, then you'd need to embed the controller in a navigation controller:
let navController = UINavigationController(rootViewController: thirdViewController)
self.present(navController, animated: false)
If you prefer to keep this within the storyboard, then you need to provide a identifier for the UINavigationController and insatiate that in your function.
The above button is a navigation bar item that will only be displayed on the navigation bar . For achieving your desired result , you first have to embed the navigation controller at least in your second viewcontroller and then you should do a push segue rather than modal . Navigation controller can be added by
whith your second viewcontroller selected go to Editor\Embed In\Navigation Controller
for pushing the viewcontroller programatically onto user navigation controller's stack use
self.navigationController?.pushViewController(nextViewController, animated: true)

Navigation bar not displaying popViewControllerAnimated() not working

I'm pretty new to swift development but I am trying to implement a back button in my application.
I have the following layout in my Main.storyboard
As seen in the picture the navigation bars display however when i lunch my app they are not visible.
I also have tried using a button that will take me back to the previous view with
self.navigationController?.popViewControllerAnimated(true)
but it has not worked
Update:
The image above doesnt show the initial controller which is my ViewController
the problem is that All Routes is actually a PageContentViewController which is called from ViewController which checks for fb login than calls:
dispatch_async(dispatch_get_main_queue()){
self.setViewControllers([self.getViewControllerAtIndex(0)] as [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
}
So i cannot change my initial view controller.
I dont know how I can get around this problem.
Is there a way to do it from Main.storyboard or a programistic solution ?
Embedding my initial view in a navigational controller and setting it to the initial view has worked.
Even though it doesnt look right on the preview because my initial view calls the other views programmatically it works correctly on the device

Programming Transition Loses Navigation Bar

I'm having an issue with my main.storyboard file. I changed the settings of my app so that the start screen is the main.storyboard file, rather than LaunchScreen.xib. The initial ViewController is the NavigationController, and the second is my SplashScreeViewController. (I created my own splash screen in the storyboard so that I could change it with additional code.) I use a line of code in my splash screen to later transition to the second view controller. Here it is:
var controller:UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("Second") as! ViewController
controller.modalTransitionStyle = .CrossDissolve
self.presentViewController(controller, animated: true, completion: nil)
For some reason, when I transition to that second ViewController, the navigation bar that should be at the top (of the second ViewController) isn't there, opposite of what was shown in the main.storyboard file. I tried to add an invisible, disabled button to the splash screen as to add a connection between the two view controllers, and therefore adding a navigation bar to the second, but when the splash transitions on its own, no navigation bar appears on the second.
Is there a way I could have a navigation bar on my second view controller without dragging one in, nor programming it in? I would like to use the one Xcode provides when you create a new connection between controllers.
Thanks in advance to all who reply.
*(I apologize for the lack of pictures to help describe my problem. I don't have enough 'reputation' to do so.)
You need to embed your Second view controller on a Navigation Controller, and then instantiate that navigation controller instead.
This might solve the problem - It looks like you are presenting a modal view controller when you probably want to be pushing your view controller from your initial navigation controller with pushViewController

Display Modal ViewController in PageViewController

I have a master page in my application that is based on PageViewController. On that master page I have a side bar that provides options to the user. One of the options is to display "About" information regarding the application. When the user click the About button in the side bar, I want to display my AboutViewController as modal. It appears all my linking up is correct however when I click the About menu option in the side bar, the whole screen simply goes black (which is the background color or my AboutViewController) and none of the content in my AboutViewController is visible.
Here is the code for my PageViewController. The highlighted code is the code that displays the modal view controller.
Here is a screen show of About View Controller Scene that I am trying to display.
Where is a screen shot of what the app looks like before I click the About button:
This is how a click the About button:
This is what I get after I click the about button:
Any suggestions as to what I am doing wrong?
UPDATE: Per the comment provided I updated my code as follows and I am still having the same problem.
gobj_sideBar.showSideBar(false)
iobj_AboutViewController = AboutViewController()
iobj_AboutViewController?.iobj_CloseAboutInfoDelegate = self
iobj_AboutViewController!.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
// Cover Vertical is necessary for CurrentContext
iobj_AboutViewController!.modalPresentationStyle = .CurrentContext
// Display on top of current UIView
self.presentViewController(iobj_AboutViewController!, animated: true, completion: nil)
Also - I don;t believe a blank page is being displayed as in the code for my About View Controller I do have the following line of code which turns off the status bar and the status bar is not visible on the scene displayed when I click the about button.
override func prefersStatusBarHidden() -> Bool {
return true;
}
OK So I switched to using Modal Segues as suggest and that mostly works. The only challenge I have now is that I want the About View Controller to display as a small popup type view but instead it is taking up the full screen as seen below:
These are the properties I have set for my About view controller. Any idea how I should change it so the view comes up as a popup type window where the background is grayed out but the About view does not take up the entire screen?
I am not experienced enough to tell what's wrong but I am spotting some mistakes in your code :
modalTransitionStyle and modalPresentationStyle are to be set on the presented view controller not on the presenting.
You instantiate an AboutViewController, save a reference to it and set self as its delegate but in the call to presentViewController(...) you instantiate another AboutViewController
Also consider that the black is not the background color of your About scene but instead the color of a blank screen.
If I were you, I'd use a segue for that about scene as well, it's less error prone. And instead of delegation to dismiss the About view controller, try an unwind segue.

Why does the tab bar item not show up?

I am developing an App that has the following set up:
There is a login screen; if the login is successful, then the tab bar view is opened. All views are created in main.storyboard. The opening is handled as follows:
instantiateViewControllerWithIdentifier("personalViewController") as! PersonalViewController
self.presentViewController(vc, animated: true, completion: nil)
It does open my new view controller, but the bar items are not visible. Anyone knows how to fix this?
Thanks!
You have to open the TabBarViewController instead of the viewcontroller that is inside of the tabbar viewcontroller.
I recommend just looking at the documentation in XCode. All documentation is written in Swift and Objective C so it is very easy to translate between the two languages. Also read apple's swift basics to understand this code translation better: https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-XID_467
presentViewController is going to open the personalViewController as a modal view. If you want to push the view onto the navigation controller stack (i.e. open it like a new screen) then you could/should use:
self.navigationController?.pushViewController(viewController: UIViewController, animated: Bool)

Resources