开发者

How to remove UINavigationController first view in stack after used?

开发者 https://www.devze.com 2023-02-20 23:38 出处:网络
I have a UINavigationController which has a loginview that appears once the app has loaded. Once the user clicks Login, we push the next view onto the stack开发者_Go百科 and it appears. I want the us

I have a UINavigationController which has a loginview that appears once the app has loaded.

Once the user clicks Login, we push the next view onto the stack开发者_Go百科 and it appears. I want the user to not be able to go back to the loginview.

How do I remove the loginview from the stack after the next view is loaded?

Note: It is a requirement that the only container of the app is a UINavigationController.


You can use setViewControllers:animated: to modify the controller stack, but I'd encourage you to reconsider whether you really want your login view controller to be the root of your navigation stack. When users see a navigation controller, they expect to be navigating up and down a hierarchy of screens organized in a tree structure. Changing the root of that tree undermines the metaphor somewhat.

Consider using modal presentation to communicate the the fact that the login experience falls outside of your app's main hierarchical navigation structure. Here are a couple options:

A. Start on login view controller, and present the navigation controller modally.

If your login view controller is always going to be the first screen the user sees, you could add its view directly to the window without the navigation controller. Then once the user logs in, create the navigation controller and present it by calling presentModalViewController:animated: from your login view controller.

B. Initialize the navigation controller with its true root, and present the login view controller modally.

This option may be worth considering if the login prompt isn't always the first view the user sees, especially if the login prompt can pop up in other contexts. For example, I used this approach in an app that allows the user to access some sections while offline or anonymous. The login prompt gets presented modally when the user tries to access content requiring authentication.


Remove the back button, by setting the backButtonItem, on the navigationItem of the login controller, to nil.


In above case your loginview Controller will be called root controller for your UINavigationController

Read below How to remove Root controller of UINavigationController

http://starterstep.wordpress.com/2009/03/05/changing-a-uinavigationcontroller%E2%80%99s-root-view-controller/


I found that by just setting the ViewControllers property, that would do the trick.

(We use C# and .NET to build iPhone apps with MonoTouch)

public override void ViewDidAppear (bool animated)
{
   NavigationController.ViewControllers = new UIViewController[] { this };
}


use NSUserdefault to set bool check value to verify to show login page or next page

for example while login page u will get username password then send it to server and u will recieve the result as success or fail

if success then set the Bool in NSuserdefault to yes

and push nextview after successfully login.

if next time user come to ur app u have to first check out NSuserdefault for that bool value

according to that u can push nextviewcontroller or login page.

that's it.

in nsuserdefault u can specify string for key instead of bool

after succesfull login set isLogined to yes

NSUserDefaults *std = [NSUserDefaults standardUserDefaults];

[std setObject:@"yes" forKey:@"isLogined"];

if not set NO

in before push login page just verify if the isLogined yes or no

according to that u can push login page or nextpage

to verify

[std stringforkey:@"isLogined"];

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号