Switch focus between two visible viewControllers (swift) - ios

I currently have a viewController(#2) on top of another viewController(#1). ViewController is displayed as a little modal like in the picture below and has functionality completely separate from viewController 1.
The current focus (intractable UI) is on controller 2 because it is on top, but I want to interact with the content on controller 1 with controller 2 open. How do I shift focus between them so that I can interact with both interfaces interchangeably and keep both in view?
ViewController 1 segues to viewController 2 by using "present modally" and viewController 2 is visible by setting presentation to "over current context".

There is no way to achieve that because your second view controller is presented modally. It covers everything of your view controller 1 so that you cannot interact with it. If you really want user to interact with both part of your screen, you need to replace your view controller 2 with a UIView
If you really want to keep the second View controller, add a Container View to your storyboard and make a segue connection to your second view controller, like this

Related

Navigation Controller with TableView

I have a UIView which is embedded inside of a NavigationController. When the user clicks on a cell in a TableView he is taken to the UIView. However, the UIView pops out from the bottom instead of sliding out from the right side. I have the segue set to Show, so I am not sure why it is doing this.
The slide-in from the side behavior only works when all of the child navigation controllers are children of the same UINavigationController. This requirement includes the "root", or first, child. In your case the root child is the UITableViewController.
It will look like this in Storyboard:
UINavVC ---> RootChildVC ---> SecondChildVC ---> ThirdChildVC etc.
A show segue is contextual. If it is as in the diagram above, it will be a horizontal slide.
In any other situation at all, including a hand-drawn segue between two arbitrary VCs, a show is interpreted as a modal presentation which comes in from the bottom and slides back down. You also don't get the automatic "back" button installation because there is no "navigation" relationship detected.
You're probably confused and need to re-do your Storyboard into the above simple idiom. If you're segueing between "cousins" that is VCs whose direct parents are different UINavigationControllers, they fall under "any other situation".
A Navigation controller shouldn't be embedded inside another navigation controller.
remove root view relationship between View and NavigationController, delete the NavigationController and set "show" segue directly from TableView to that view.

Set initial view controller of a navigation controller

I'm developing a simple iOS app to learn Swift and iOS programming.
I was wondering what would be the "best" way to present, on app launch, a different View Controller than the first one in the Navigation Controller stack.
Consider this storyboard diagram:
The Tab Bar Controller is the initial View controller and "View Controller 1" is shown at app launch inside the navigation controller. Since "View Controller 1" will be almost never used, I'd like to show "View Controller 2" instead, with the "back" button pointing to "View Controller 1". To save time and memory, I'd prefer non to load "View Controller 1" at all, since I already know what data has to be shown in the second view controller.
Both the view controllers are actually Table View Controllers and the selection of one of the cells in the first VC triggers a segue to the second. However the user would usually only need to see the second VC as if the first cell of TVC 1 was selected.
Because you want to be able to "go back" to the first VC, it needs to be put below the second one. My suggestion is to programatically set up the first VC as the root view controller in appDelegate didFinishLaunchingWithOptions and immediately push/present VC2. In this way the first VC won't be shown and therefore costly views loading/laying out subviews can be omitted.

Difference between navigation controller and viewcontroller?

Difference between navigation controller and viewcontroller?
I mean how can we decide when to use navigation controller or a normal view controller?
Just my two cents:
A UIViewController represents a single view and you can put buttons in this view controller to segue to another UIViewController. If you want to segue back to the first UIViewController, you will have to worry about putting a button in the second view controller that leads back to the first. If you are drilling down into view controllers, this can be tedious having to remember to give the user a way back to a previous view controller.
A UINavigationController does a lot of this tedious work for you. As mentioned, it contains a stack of UIViewControllers. It will create a navigation bar at the top that will allow you to easily go back up the hierarchy of view controllers.
In short, if you have a hierarchy of view controllers that you want the user to easily navigate around, inbed your UIViewControllers into a UINavigation controller.
UINavigation Controller is a combination of 2 or more view controllers,those are connected through "segue" feature of "Ios". Benefit of using Navigation Controller is that we can navigate between different screens easily with default "Back" button on each screen . We don't need to give any individual button to move back onto previous screen.
Whereas a ViewController provides a single screen & we can connect more screen using "segue" but we also have to design a "Back" button to navigate onto previous screen.
We should use Navigation Controller , in case where one option resides into another one.Like in an iPhone settings ->Mobile Data Options->Voice->4G or 3G or 2G. It's a hierarchy of menus so here navigation Controller is better option than using UIController.
We should use UiController with "segue " , in case where
we have to choose one option among multiple.Like -
Photos ->There are many folders in which , any one is selected, that are Favourites or People or Places .
Here's a very brief, high-level overview.
Whereas a UIViewController can be thought of as representing a single 'screen', UINavigationController, as the name implies, is used as a means of being able to navigate multiple 'screens'.
From the documentation:
The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This navigation interface makes it possible to present your data efficiently and makes it easier for the user to navigate that content. You generally use this class as-is but in iOS 6 and later you may subclass to customize the class behavior.
Please see the rest of the UINavigationController documentation here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/index.html
Okay, Thank you everyone for helping me to find out a clear answer on this.
Navigation Controller consists of navigation bar and tool bar to move in and out from view controllers present in navigation stack.Therefore there can be many view controllers in Navigation Controller.
In view controller we don't have this facility and it represents a single screen view.
Please correct me If I am wrong.
See the Navigation Controller discussion in the View Controller Catalog.
Bottom line, a navigation controller actually is a view controller, but it just happens to be one that presents and navigates between other view controllers.

NavBar doesn't appear when segue is called programmatically

I have an iOS app with 3 views. I am using a "push segue" to move between them. I have linked a push segue from a button in First view to Second View. For moving from second to third, I cannot have a button. I have a list of items and the person can click in any of those to move to third(and last) view. So I added a segue in storyboard and calls it programmatically. The third view is opening properly except that the nav-bar is no longer there.
[self performSegueWithIdentifier: #"moveToFilesSegue" sender: self];
I can live without nav-bar. But the real problem is that I cannot do a push segue from my third view to any other view.
So my question is whether there is a way to call a segue from second view to third view in such a way that the third view also has the navigation controller that the first two have by default(ie navbar is also visible in third segue). There is some break in navigation because of me calling a segue programmatically.
So a few comments. If you would like to be able to get to the two other views from any view at any point in time, then I would suggest using a tab bar controller rather than a navigation controller.
If you must use a navigation controller, then you should keep the first view controller as the root view controller. Imagine then tapping a button that pushes the second view controller. Then say you tap a button to get to the third view controller from the second. What you should really do is perform an unwind segue from the second and then immediately perform a segue to the third. The animations will be a bit undesirable by default since it will probably show the pop and the push, but to treat it like a tab bar, you could just disable the animations on the pop and push.
To implement, keep an int variable in the first view controller (btw.. you can do this by keeping the int in the navigation controller as well if you want). In the viewDidAppear, check the int variable. If it == 1 then push the second view controller. If it == 2, then push the third view controller. Else, don't do anything. When a button is pushed in the second view controller to view the third, unwind the second view controller, but in prepareForSegue set the int variable in the destination view controller to 2 . Thus, when the first view controller appears, it will immediately push the third view controller.
I know it is a bit annoying, but you don't really want to keep pushing the same view controllers over and over again without unwinding.

What's the proper way to replace a UIViewController with a UITableController without a navigation controller stack?

Assuming I start with a blank project, and I add 2 views (UIViewController,UITableController).
What's the proper way to jump from a UIViewController to a UITableController without a navigation controller stack?
Ex: think of a welcome page, click here to continue, and it takes you to the table controller.
Thanks!
If these are the ONLY view controllers, you can do it by reassigning the rootViewController property of the UIWindow Just set it to whichever controller you want to display, and it will do the rest.
I would not have 2 view controllers then in that case if it's a welcome page type of thing. I would have a UIViewController with a UITableView in its view and a view over the top of the table view at the start which when you tap a button, gets hidden - i.e. just 1 view controller.

Resources