Falken Creative
Falken Creative

Reputation: 13

pushing a view into stack below current root view

I'm trying to implement a calendar like interface, with left and right arrows that allow users to scroll back in time/forward in time. To do this, I'm using a navigation controller, and pushing/popping views on the stack.

However, what if I'm currently viewing the root view, and I can't pop the view in order to get the correct animation direction if I'm trying to navigate back in time?

I found a post on Stack Overflow last week that demonstrated a method where the new view would be pushed onto the stack below the current root view, allowing the root view to be popped off. It was just a couple lines of code -- primarily getting an array of the current items in the stack and somehow pushing the new view below the currently active view. Unfortunately, I can't seem to find that particular post any longer...

Has anyone happened across the same link, or might be able to point me in the right direction? I had this working correctly earlier, and due to a computer malfunction lost a bit of my work.

EDIT:

With some experimenting, I have this partially working...

// create new view controller
ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

// add below root        
NSMutableArray *allViews = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
[allViews insertObject:viewController atIndex:0];
[viewController release];

self.navigationController.viewControllers = allViews;
[[self navigationController] popViewControllerAnimated:YES];

[allViews release];

It does seem to be leaking memory, however -- if I do an NSLog of the allViews array, every time I go forward in time and then back to the previous view it seems to add an extra view to the array that doesn't get taken off later. This will work for now, but hopefully I can get this issue fixed.

Upvotes: 1

Views: 261

Answers (1)

Vincent Bernier
Vincent Bernier

Reputation: 8664

UINavigationController Class Reference
I think that you are talking about the @property(nonatomic, copy) NSArray *viewControllers
Quoting the reference :

Discussion
The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.
Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to NO.

Is that the information you are looking for?


For what you are trying to do you might consider something in UIView instead.

transitionFromView:toView:duration:options:completion:
Creates a transition animation between the specified views using the given parameters.

Upvotes: 1

Related Questions