Swift 4.2 Segues: ViewControllers Stacking Instead of Replacing? - ios

Pretty simple problem - now that I'm using Swift 4.2, my segues are "stacking" the view controllers physically. When I segue, the new view controller is not brought to the top of the screen and can be dragged down to go to the view controller before it. When I segue, I want the previous view controller to be entirely covered by the new one. How do I achieve this? Am I forced to use a navigation controller now?

What you are seeing is a change in the default modal presentation style for iOS 13. There are different possible ways to address it depending on your intent. These question and answers cover those possibilities:
Presenting modal in iOS 13 fullscreen

change the presentation style
for example
let VC1 = self.storyboard!.instantiateViewController(withIdentifier: "sideMenu")
VC1.modalPresentationStyle = .fullScreen
self[![enter image description here][1]][1].present(VC1, animated: true, completion: nil)
or if you are using storyboard, check the segue properties

Related

Dismissing modally presented ViewController always throws me back to root

I've had this issue for months with multiple views, both Apple provided like ImagePicker and VCs from storyboard.
I believe that it has something to do with the underlying views we have both a tab bar controller and navigation controller in most views.
Strange thing is using some open source views from pods does not cause this bug.
So I'm two views deep on a navigation controller and present another view modally on top with present(vc, animated: true, completion: {})
Works like a charm, now dismissing that view with dismiss(animated: true, completion: nil) throws me back all the way to the initial view or root view of the navigation controller, had both happen before, depending on the presented view.
Update:
Build a sample project trying to reproduce the behavior but failed. Drew a reduced diagram to better explain the current bug behavior.
Also noticed that if I'm invoking the post view one step earlier in the Fandom view it works as expected.
In my case i am using UITabBarController, and I wrote code in viewWillAppear of UITabBarController
self.selectedIndex = 2
so when i present any thing from any controller whose parent is UITabBarController and when i dismiss that it automatically open third tab of UITabBarController.
Maybe you explicitly wrote any code to select specific index of TabBar.
Maybe this is useful for you or anyone else.

Presenting Modal ViewController from (Table)ViewController inside a NavigationController inside a TabBarController

When I try presenting the modal controller right from the table view controller (could be a normal view controller as well), it appears behind the tab bar and looks quite ugly as I'm using a blur effect on it. I am using a navigation controller because I need to have a bar at the top and, after research, found that's the best way to do it.
I have found that doing something like:
self.parent?.parent?.present(ModelViewController(), animated: true, completion: nil)
when wanting to present the modal controller works. However, I imagine this isn't very safe. What is the correct way of doing this?
In order for the ModalViewController to present in front of the tab bar, its modalPresentationStyle has to be set to overFullScreen. So for instance when initializing the ModalViewController:
self.modalPresentationStyle = .overFullScreen (Swift 3 syntax)

Swift create 'universal' segue in tab bar app

I'm a swift newbie and I've got a simple question which I hope someone can help me figure out.
I have a multi-tab app. I created some segues from the tab view controllers on the Stopryboard. I've given the segues identifiers and I'm calling them from my Tab1ViewController code using performSegueWithIdentifier("tab1ToMyTarget", sender: sender) no problem.
However, I'd like to be able to call the segue from any of the app's tabs without creating new segues from the other tabs' view controllers (i.e. I don't want to create "tab2ToMyTarget" - I presume there's a better way!).
My question: Do I create these 'universal' segues on the tab bar view controller (e.g. "tabBarToTarget") (and if so how do I call it from one of my tab view controllers)? ...or...
Do I keep the segue from a single tab view controller (tab1ToTarget) and call that segue from a sibling tab view controller somehow?
First, set the view controller that you want to go to's storyboard Id. Then run this:
let vc = storyboard!.instantiateViewControllerWithIdentifier("someViewController")
self.presentViewController(vc, animated: true, completion: nil)
You cannot use the same segue to open a controller from a different one. It's better to instantiate a view controller with its storyboard id and then present/show based on the flow.

SplitviewController in navigationviewcontroller

Hey I am building my first ios application using xcode. I'm a total noob in xcode and swift and I am trying to use the storyboards to set-up my app. Here's a link to the prototype http://adobe.ly/1q5Imf6.
Basically my issue is where I want to do the split view on the resellers page. I want to use the splitviewcontroller only on the page, so after an intro viewcontroller in a navigation controller. like this
I read somewhere that a splitviewcontroller must be the initial view controller, however this works if I use segues that pop up modally. But when I do that I don't really have a navigation bar anymore on the page. I only have the splitview, but there must be the option to go back.
Am I doing this completely wrong or is there a simple fix to get what I want?
If you want to present your UISplitViewController modally, then you need to wrap into UINavigationController. After it you can add UIBarButtonItem in your UISplitViewController and set an action to dismissViewControllerAnimated(true, completion: nil)

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