views:

283

answers:

1

I have a uinavigationcontroller. After logged in i want to remove viewcontrollers like RegisterViewController,LoginViewController etc from UInavigationcontroller stack..

I mean i have to remove a particular view controller from stack ? How its possible. ?

I checked this post

http://starterstep.wordpress.com/2009/03/05/changing-a-uinavigationcontroller’s-root-view-controller/

So we can take it into an array like

NSArray *allviewcontrollers= [(UINavigationController *)navigationController viewControllers];

But how to do further process.. This question is hunting me for long time..Please answer me ..Thanks in advance

+2  A: 
NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: navigationController.viewControllers];
[allViewControllers removeObjectIdenticalTo: removedViewController];
navigationController.viewControllers = allViewControllers;
Costique
Thank you for answering me.But i have doubt in second sentance.LoginViewController * loginViewController = [LoginViewController alloc];[allViewControllers removeObjectIdenticalTo: loginViewController];But it didn't worked..But when i tried [allViewControllers removeObjectAtIndex:0];it worked. I want something like that you answered. i also tried [allViewControllers removeObjectIdenticalTo: @"LoginViewController"];But it didn't worked. Please clarify me. Thanks ...
Sijo
I had some doubts about how to remove the particular view..And i post a question for that and got the answer..http://stackoverflow.com/questions/2100450/how-to-check-a-uiviewcontroller-is-present-in-uinavigationcontroller-stack/2101034#2101034
Sijo
Somewhere in your code you created, say, the LoginViewController with +alloc and -initWithNibName:bundle:. That might be your app delegate, I don't know how your app is architected. Anyway, to reliably remove the controller you have to keep a reference to it (e.g. as an ivar in your app delegate). The "removedViewController" in the above snippet is just that reference. Yes you can traverse the array of view controllers looking for the controller of a particular class. But what if one day you'll have two or three of them as you extend your app? My 2 cents.
Costique
I understand that your method is the best way to remove a viewcontroller from uinavigation stack. Am very new to objective c. So confused with "reference to an object". I tried this one .. [allViewControllers removeObjectIdenticalTo: myDelegate.nonLogginedViewController]; Where in my Appdelegate i wrote @property (nonatomic, retain) NonLogginedViewController *nonLogginedViewController;and @synthesize nonLogginedViewController;Is it only needded to keep a reference to nonLogginedViewController ?Thanks in advance..
Sijo