Modal view doesn't cover whole screen - ios

I have an app that I need to display a pin code screen every time the app is opened. I'm successfully displaying the modal view, but it doesn't cover the navigation bar at the top, and it doesn't cover the tab bar at the bottom. I believe it's because of how I'm presenting it, but I'm not seeing a way to change it.
This is how I'm presenting the controller
let newVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginView")
let view = window?.rootViewController as! UITabBarController
view.selectedViewController?.show(newVC, sender: nil)
This is the storyboard to give you an idea of the app.

The problem is your use of UIViewController's api, show. The function is overridden by UINavigationController in this case and push will be used to present the view controller. If your plan is to modally present a view controller, rather use present
selectedViewController?.present(newVC, animated: true, completion: nil)

Related

Issues using pageSheet in iOS 12, Xcode 10

I'm trying to recreate the effect where the view controller underneath the one I'm presenting onto the user's iPhone is positioned behind the presented view controller so you can see the top of the previous VC.
#objc func showSteps() {
let vc = UIStoryboard(name: Storyboards.Main.rawValue, bundle: nil).instantiateViewController(withIdentifier: HowToSteps.four.stepAsString())
vc.modalPresentationStyle = .pageSheet // I've also tried the other enum options here to no effect
let nc = UINavigationController(rootViewController: vc)
present(nc, animated: true)
}
However the presented view controller just comes up as full screen without the ability to see the view controller underneath behind it.
Any help here would be appreciated. Thanks!
Edit:
The effect I'm going for:

Add tab bar for all the screens iOS(swift)

I am working with UISplitViewController. I have UISplitViewController which contain UITabBarController. So I want to display tab bar in all the screen through out the application (Even in detail screen of UISplitViewController for iPhone). Please see the approach:
use segue to move from one controller to another controller or move via navigation so in the next controller your tabbar will be show
just like if u want to move from A to B Controller set stroyboard id ie "SecondVc"
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "SecondVc")
self.navigationController?.pushViewController(vc, animated: true)
or just make connection using storyboard

iOS TabBarController shows only black screen

I have created a TabBarController with 4 UIViewControllers. However, when I want to show one of the ViewControllers in the TabBarController with:
func gotoMainAppVC()
{
let mainVC:SearchVC = SearchVC()
self.present(mainVC, animated: true, completion: nil)
}
I only get a plain black screen. What am I doing wrong?
This is not how any of this works.
I am not sure what self is in your context but I expect it is either a tab bar controller or one of the view controllers on the tab bar.
By calling present it means you want to present a view controller on a current one which by default brings a new fullscreen view controller from bottom upwards.
Since you have created a new instance of view controller by calling SearchVC() this is not the view controller that you see in your storyboard. You may create any instances of any of your view controllers but in your case if you designed SearchVC in a storyboard you want to actually use that version of it. To do so you need to set storyboard id inside your storyboard. After you have done that you should initialise it as using:
UIStoryboard(name: <#T##String#>, bundle: nil).instantiateViewController(withIdentifier: <#T##String#>)
as in
let mainVC:SearchVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "TheIDIHaveSet") as! SearchVC
But again this will not give you the view controller that is inside your tab bar but create a new instance. And it will not instert it as one of the tabs but present a new full screen view controller.

Go back previous ViewController from NavigationController in TabViewController

I got the problem is I cannot make go back previous ViewController of different storyboard from NavigationController in TabViewController.
I've already tried with
_ = navigationController?.popViewController(animated: true)
unfortunately, it does not work. And I know that it can be going back with segue but it's not good practice. Please let me know how to do it. Thanks. Following is my hierarchy.
I had the same issue. In this case I am on a different Storyboard and want to return to the Main Storyboard and present the first view controller. Since this controller is embedded in a Navigation Controller that is embedded in a Tab Bar controller, you must instantiate the Tab Bar Controller. Be sure to set the indentifier on the Tab Bar Controller as "TabBarController"... or whatever you like.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
self.present(controller, animated: true, completion: nil)

Multiple Storyboards - Multiple Navigation Controllers

I am breaking up my project into multiple storyboards. I have a login storyboard with a navigation controller. The last step "Complete Registration" takes you to main.storyboard.
This leaves the navigation controller in place, and the back button takes you back to register. I obviously don't want that. I know I can hide the bar by using:
self.navigationController?.navigationBarHidden = true
But how can I leave the navigation controller?
Any help would be greatly appreciated!
The easiest and most correct way to do this would be to make your login screen a modal view. If you don't want to give your user the ability to go back, then you shouldn't use a push segue. You should use a modal view.
In the iOS Human Interface guidelines it says that modal views should be used for "a self-contained task [that] must be completed—or explicitly abandoned—to avoid leaving the user’s data in an ambiguous state."
A modal view will make it so your login and your main screen have to be in separate Navigation Controllers.
In the completion handler of the "Complete Registration" action you'll want to use the following code.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateInitialViewController() as! (TypeOfViewController)
self.presentViewController(viewController, animated: true, completion: nil)
If your main.storyboard is already embedded in a NavigationController (Initial view controller is a UINavigationController) then you'll have to do that a little bit differently.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateInitialViewController()
self.presentViewController(viewController, animated: true, completion: nil)

Resources