0

I am currently using this guide such that I can replace the root controller with another view controller. http://starterstep.wordpress.com/2009/03/05/changing-a-uinavigationcontroller%E2%80%99s-root-view-controller/

Currently, I have gotten that down on my app.

Consider the following scenario, View A (root) -> View B

On View B, there is a boolean value called firstLine (set to YES in viewDidLoad) which is used for a parsing algorithm. The algorithm works perfectly when we go into the view on the first time. (view A -> view B)

However, this new scenario breaks my parsing algorithm,

view A -> view B (pressed back) -> view A -> view B ( breaks )

This is where the boolean value (firstLine) is alternating weirdly when it is suppose to be set to YES when we first enter into the view. I am starting to believe that the first view B is still running on the background; thus, I tried popViewController but that didn't really work. It gave me a black screen, which is obviously what I don't want.

Any ideas?

EDIT: SOLVED

Turns out I was using an NSTimer and that kept on going off on its own. Therefore, I had to invalidate it when I left the view.

freedom
  • 751
  • 1
  • 10
  • 20
  • Im not qute sure i understand you. do you want firstline = YES when you get back into View A? You should set the Value in ViewWillApear or viewDidAppear, then. – katzenhut Feb 21 '13 at 22:54
  • this boolean value is set in view B at viewDidLoad I am using this boolean value in view B for parsing. – freedom Feb 21 '13 at 22:58

2 Answers2

0

Have a look at the answers to this question Looking to understand the iOS UIViewController lifecycle This will help you in determining when to set your flag in your view and what happens going from one UIView to another.

Community
  • 1
  • 1
Mindeater
  • 322
  • 3
  • 9
0
[self.navigationController setViewControllers:myPreparedNewVCsStack 
animated:YES];

You can filter, move and replace any view controllers:

NSMutableArray *tempStack = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];

[tempStack filterUsingPredicate:[NSPredicate predicateWithFormat:@"class != %@", [AViewController class]]]; // the predicate can be even @"firstEnter == YES"

Your last view controller in new stack will be the top one!

iiFreeman
  • 5,165
  • 2
  • 29
  • 42