0

I am having some problems with popping items from the navigation stack and no idea why its behaving like it is.

Stack
A classA
B classB
C classC
D classD

At stack D I create another classD and add it to the stack.

Stack
A classA
B classB
C classC
D classD
E classD

Before I create E and push it on to the stack, I do a pop to get rid of D so that the stack becomes

Stack
A classA
B classB
C classC
E classD

However when I pop, the self.navigationController.viewcontrollers becomes 0 and im stuck on C with E not becoming visible. Why does the pop just remove everything and go to C?

At C in didSelectRowAtIndexPath I create a ClassD and do:

[self.navigationController pushViewController:ClassD animated:YES];

At D in didSelectRowAtIndexPath I create another ClassD and do:

[self.navigationController popViewControllerAnimated:NO]; //remove current and replace with new
[self.navigationController pushViewController:ClassD animated:YES];

But it doesn't seem to do what as expected. I sense the transition from pop to push seems to be too fast nothing is appearing? Any ideas?

thomas
  • 5,637
  • 2
  • 24
  • 35
fes
  • 2,465
  • 11
  • 40
  • 56

1 Answers1

0

it sounds like the popViewController is also setting the self.navigationController to nil. if self.navigationController is nil then [self.navigationController anyMethod] does nothing.

try this (not tested):

UINavigationController *nav = self.navigationController;

[nav popViewControllerAnimated:NO]; //this pops myself
[nav pushViewController:anotherInstanceOfClassD animated:YES];

if this causes the problem that self is beeing destroyed then just add the following line before pop:

[[self retain] autorelease]
Community
  • 1
  • 1
thomas
  • 5,637
  • 2
  • 24
  • 35