navigation controller stack uses too much resources - ios

I am building an application that have an introduction at first when users do not login.
If they log in, when navigation controller will push to Home View Controller, but the Introduction View Controller is still in the stack and use a lot of resources. How can I prevent that?

You can set the navigation controllers property to array holding ur homeview controller alone. Or set the home view controller as root of navigation controller.

You can't prevent it from being there necessarily as that is a function of how you associate your views.
If you are happy with your current transitions (UI) then you should add a bit of code after the transition has completed which gets the nav controller view controllers array, removes the first object (the login / intro VC) and saves the new array.
If you want to change the transitions then you could look at presenting the login / intro as a modal so that when it is dismissed it is automatically destroyed.

Related

Changing the number of View Controllers affected by Navigation Controller

So I have a navigation controller that is at the beginning of a series of view controllers. The series consists of 5 view controllers, but I want the navigation controller to only use the first 4 view controllers. Im not sure if there is a way to change the relationship between view controller 4 and view controller 5 so that view controller 5 and the rest of the app are not affected by the navigation controller.
Im not sure if there is a way to change the relationship between view controller 4 and view controller 5 so that view controller 5 and the rest of the app are not affected by the navigation controller.
There are a number of things that you could do:
Remove the navigation controller entirely and make your "view controller 5" the window's root view controller.
Set the navigation controller's array of view controllers to an array that contains only "view controller 5." This would effectively make that view controller the navigation controller's root controller, and from there you could just never push another controller onto the navigation stack.
Keep the current relationship, but hide the navigation bar and prevent the user from going back to "view controller 4."
Rethink your user interface. For example, if your first four view controllers are meant to lead the user through some set of initial questions, a login procedure, etc., then you could make "view controller 5" the app's main view controller, and present the navigation controller containing the controllers 1-4 modally.
Of those, and without knowing what you're actually up to, I believe reconsidering your UI is probably the best plan. Users should generally be in control of your app instead of the other way around, and they should never wonder why they can't get back to some part of the app that they've seen before. Also, it's poor form to break behaviors that users have learned to expect, and changing the user's ability to navigate through a series of view controllers would be a prime example. Using a modal presentation of the navigation controller with the first four view controllers should be fine, though.

Dismissing and presenting View Controllers - An Explanation?

Recently, I've been reading about the concepts behind dismissing and presenting View Controller. I've been able to pick up on the ideas of dismissing the previous View Controller from the destination View Controller but I can't find an answer to a few questions that have been on my mind for quite a bit.
Scenario 1: I have a login page and after the user enters their credentials, it performs a segue to another View Controller. Is it necessary to dismiss the login page afterwards or is there no reason to?
Scenario 2: I have two normal View Controllers (VC1 and VC2). If I perform a segue to VC2, will I need to dismiss VC1?
I'm mainly confused regarding the idea of when it is necessary to dismiss View Controllers and when it is not necessary to do so.
I'd appreciate it if anybody could help clear these questions up for me.
Scenario 1: After performing a segue, it switches between your view controllers [ automatically dismisses the current ViewController and presents a new one ].
So, there's no reason to dismiss the login page.
Scenario 2: No you don't need to dismiss VC1.
1) When you go from login controller to second controller you just need to present the second controller and no need to dismiss first because if you are using navigation controller as a part of your segue all the view controllers are arranged in form of a stack . So second comes on top and first goes below it.Now if you need to got from second to first you can either dismiss your controller or pop your controller.When you dismiss a controller it is not popped from stack instead just moves behind and let the first controller come on top and when you pop a controller it removes itself from stack as well.
2) Same goes for your second question no need to dismiss first when you go from first to second controller.
If there is a view controller which in most cases will be used only once (like login or settings etc.) — and especially if, after you’re done with it, it makes sense to return to the view controller you were on before — the best is to present it modally and dismiss it when you’re done. The rest of your view controllers stay in memory after the user can no longer see them, and this is expected behavior given the way Apple has created the methods for presenting and dismissing view controllers.
It is my understanding that in the Android world, this is not the case -- the default there is that when a new view controller is presented, the old one really does goes away.
As you know once user has signed in, log in screen not opens until user log out. So you should remove log in view controller from stack, it should not keep in memory. For this task, do not directly perform segue, you should change root view controller. There are lot of answers on stackoverflow for How to change root view controller?

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

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).

How to determine which view controller is currently active/the one displaying a view?

In my app I am queueing some local notifications, when they fire I must present a modal view. The trouble is I have numerous view controllers any one of which could currently be active and thus the one that needs to present the modal view controller. How can I determine which one is currently in use?
I am setting a navigation controller as the windows root view controller, and this can push any number of other view controllers, some of them themselves may also be currently presenting another view controller modally.
This must work on iOS 4 and 5.
I have a lot of view controllers so would like to avoid putting code in each of them to each check if they are currently the top one.
You can look at the navigation controller's topViewController property to find out which controller is at the top of the stack. This will be the one whose view is displayed.
Since you may also be presenting a modal view controller, you'll probably be more interested in the visibleViewController property, which will give you the controller for the current view whether its presented modally or pushed onto the navigation stack.
Create a variable that stores a pointer to the ViewController that was most recently pushed. Every time you push a new ViewController, update this variable. Then you'll always know which one is on the top!

Displaying a Specific View in a UINavigationController Stack

In building my application which is a tab based application, from the first tab, the user has the option to view their profile information (which is specific to the app). SO have set up UINavigationController with following view controllers:
1 - Edit profile
0 - View profile (also the root view controller for the `UINavigationController`).
The flow I would like to achieve is if a profile has not been set up (i.e. the first time the application is run), I would like to go directly the Edit Profile View, which right now is the default behaviour since that view is at the top of the stack.
The problem I have run into is, if the profile has been set up, how would I go directly to View Profile. I have looked at the documentation for the UINavgationController, and it unclear about popping a view controller off the stack. The method popToViewController:animated return an NSArray of items popped from the stack. Does that mean those view controllers are no longer available, and/or is there a better method to go directly to the view controller that I want?
If you only have two views in the navigation controller, and View is the root view controller, you can make sure that View is the one that is shown by running popToRootViewControllerAnimated: immediately before or after that tab has been selected on the tab bar controller.
If you are in a case where you want Edit to show, run popToRootViewControllerAnimated: followed by pushViewController:animated: with the Edit view controller.
When you want to pop, you can use popViewControllerAnimated: rather than popToViewController:animated. (You only have two view controllers in this nav controller, so ther is only one that will ever be popped.)
This seems pretty simple, unless I have misunderstood your question.
The array of view controllers that are returned from the popToViewController:animated aren't needed by most programs. I haven't really found a need to use this method myself, and, as I said, it doesn't look like you need it here.

Resources