how to make a page accessible from every other page in my app and able to unwind to where the segue comes from - ios

I am trying to create an on-top structure where user can go to a general page G from any other pages with a special gesture and go back to the page where s/he comes from.
Is there a way to do this while not implementing a segue and an unwind segue from every other page to page G?
Thank you!

Yes, you can do this without having a segue from each controller, but it depends on how your controller hierarchy is set up. If for instance, you have a navigation controller, and all your view controllers are pushed onto its stack, you can create one segue from the navigation controller to the one you want to go to from any of your other view controllers. You could also do this if your other controllers are embedded in a tab bar controller (the tab bar controller would present the common controller).

Related

Popping View Controller when not using a Navigation Controller?

I have searched around and all cases of using the pop to return to a previous view controller seem to be based around using a navigation controller, I am using a tab bar controller and have no real need to the navigation controller and so havent implemented it.
I load this detailed view controller via a segue based on rowindex selected in a list controller and just need to close it when they are done reading with a close button.
Is there still a method that can be used to pop a view controller without it all being housed in a navigation controllers unnecessarily?
Why don't you use a Storyboard and use an Unwind Segue to go back to the prev. View? Take a look at this Unwind Segue, hope will help you.

I need some clarity on Navigation Controllers

I have a total of 3 views. A menu, the main view where the action happens, and a settings menu.
You can access the settings from both the menu and the main view and go back using the back button provided by the Navigation Controller.
In the main view I have hidden the NavigationBar to free some space, and there's a specific button to go back to the menu. From what I know and have read, I assume this just adds more and more views to the Navigation Stack if I keep going from the main view to the menu again and again, creating a lot of views in the stack.
I'd like someone to tell me whether my assumption is true or not, and evt. explain me the whole process behind navigating and views.
UINavigationController has a property viewControllers which is the stack of view controllers that have been pushed there.
If you use push segues in your storyboard each time you trigger this segues you push the current controller to the stack.
If you have a special logic I suggest you manage controllers programmatically.
This might clear it all.
There are basically following types of Segues to navigate to any viewController
Show (Push)
Show Detail (Replace)
Present Modally
Present as Popover
And to move back use Unwind Segue
You can read more regarding this here

How to design a mechanism to manage viewcontrollers transitions, like route

I want to design a routing mechanism for management view controller transitions in objective-c.
Two view controllers, without reference to the other side of the pointer, the transition is completely controlled by the route.
How to achieve the route?
Thanks for your help.
I hope you think like this.
Route = Segue (In Xcode)
Take Two View controller
Make 1st Embed in Navigation controller (Which is must be initial View Controller)
Put One Button in 1st VC
Press Ctrl + Drag Mouse from button to 2nd VC (One popup will be show, then select Push)
Run Project
Press Button
Lol
You can use Storyboard's segues. Create view controllers and segues between them. You can use Push Segue or Model Segue. Push Segue will let you pop next view controller too, and you will have to embed your first view controller into navigation controller. For Model Segue, you can move from one view controller to another but to return to previous view controller, you will have to create another segue.
I think I find the approach to answer this question。 Here is the similar project.

Different views based on user type - Correct segue type after login?

I have a Login View Controller which is the initial view controller. Here users input their username and password, which is then sent off to the server to be checked. If the user has inputted correct credentials the server responds with some JSON data including the user type (either 'student' or 'demonstrator'). I'm using the returned user type to decide on what views the user the will see. (users will see different tab controllers)
The bit I'm struggling on is on what type of segue to perform. Push or Modal? I tried embedding a navigation controller into the Login View Controller and performing a Push Segue to the correct view, but this seems to not play nice with other navigation controllers that are embedded in the other views (title's disappear etc).
Is the modal segue type the correct one to use in this situation? The user wont be returning back to the login screen at all.
Keep in mind that you CANNOT nest navigation controllers. Pushing a navigation controller onto the navigation stack leads to the types of errors you saw with missing titles and the like. Always modally segue to a navigation controller, and use unwind segues to get back if you need to.
A push segue is used exclusively to push the destination view controller onto the navigation stack. The initial view controller must be in a navigation stack before you can push segue. If your login view is the root view of a navigation controller, then pushing the next view is the way to go.
On the other hand, which it sounds like may be your case, if your login view is your initial view and you want to segue to two different navigation controllers containing different paths for different user roles, you'll want to modally segue to the navigation controllers themselves.
Some Reference Material From Apple:
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/UsingViewControllersinYourApplication/UsingViewControllersinYourApplication.html#//apple_ref/doc/uid/TP40007457-CH6-SW1

When I should use Navigation Controller?

I don't know when I should use Navigation Controller instead of use segue with normal View Controller?
And if use segue, which different between Modal and Push segue?
Can you give me an example?
Short answer: Use a Navigation Controller with "show" segues only to implement DRILL DOWN behavior.
For example,
Navigation Controller → Authors → Books → Book
For each level below the "root" (Authors), the Navigation Controller automatically adds the title bar and back button. So on Books, the back button is automatically named "<Authors".
The child View Controllers must be connected with SHOW segues -- show segues tell the Navigation Controller "this is a parent-child relationship" and cause the expected slide-in-from-the-right transition. (To jump outside the hierarchy, for example, Books → Login, use a modal segue instead.)
The root View Controller has a navigation bar that you can add more bar buttons to, but child View Controllers don't, because it's added automatically.
FoodTracker Example
Now the odd-seeming layout of the FoodTracker tutorial in Apple's Start Developing iOS Apps (Swift) can be explained. **What's up with that second nested Navigation Controller? It's just a simple list of meals: tap a meal to show it in Meal Detail, or tap Add to and Meal Detail becomes Add Meal.
FoodTracker Storyboard
The first Navigation Controller makes My Meals the root of the drill-down hierarchy for any number of views "pushed" from there on (no further Navigation Controllers are needed just to do that).
But, Meal Detail is used for both displaying an existing meal and adding a new meal. To add a new meal, Cancel and Save buttons are needed. The second Navigation Controller allows those buttons to be added (see 3rd point above) by making Meal Detail a root.
Displaying an existing meal is a push segue, but adding a meal is a modal segue (a new meal isn't a drill-down). This is important: the reason Add Meal can't just be pushed is that the automatic back button ("< My Meals") becomes ambiguous: does it save or cancel?
Because "navigation" and "push" are very general terms, and because it's nice to get a free back button, it's tempting to think Navigation Controllers are to go from anywhere to anywhere, but the behavior is intended just for hierarchical traversal.
(This is an old question but I was also confused about this as an iOS n00b and like the OP I still had questions.)
In my experience, there is no a general rule to decide this kind of things, it depends on the usability of your future App...
Navigation controller helps the user to remember where they are in every moment, and how they can go back, but could not be the best thing to use if you have too many levels... And more important, if you are using a NavigationController or a TabBarController, you have a class, accessible from all the other ViewControllers where you can have general functionality or data...
The difference between the modal and push segue is that in the first you will always return to the parent ViewController, because you are only showing new information on top, while in the push one you are replacing one ViewController with other...
You use navigation controllers when you want to enable back button functionality. You still use 'normal' view controllers, you just embed them in a navigation controller. Then, you can push view controllers and be able to go back.

Resources