problem in passing the values in popviewcontroller - iphone

{
seViewController *seView = [[[seViewController alloc] initWithNibName:#"seViewController" bundle:nil] autorelease];
[[self navigationController] pushViewController:seView animated:YES];
[seView insert:myString];}
I am passing the seView in pushViewController its working correctly. But how to pass the seView in popViewController.

From the Apple Reference
popViewControllerAnimated:
Pops the top view controller from the
navigation stack and updates the
display.
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
Parameters
animated
Set this value to YES to animate the transition. Pass NO if you are
setting up a navigation controller
before its view is displayed.
Return Value
The view controller that was popped
from the stack. Discussion
This method removes the top view controller from the stack and makes
the new top of the stack the active
view controller. If the view
controller at the top of the stack is
the root view controller, this method
does nothing. In other words, you
cannot pop the last item on the
stack.
In addition to displaying the view
associated with the new view
controller at the top of the stack,
this method also updates the
navigation bar and tool bar
accordingly. In iOS 3.0 and later, the
contents of the built-in navigation
toolbar are updated to reflect the
toolbar items of the new view
controller.

Related

Adding navigation controller to custom designed table view which have calender view

want my table to show up only half way from the bottom of the screen, the upper half meant for the calendar view. To do this, I added a table view through code using CGRectMake specifying the (x,y) co-ordinates I wanted it to start at.
Now, I want each row of this table to navigate to a new view. How do I make the navigation controller push my new view? I added a navigation controller to my main view
TaskDetailsViewController *detailViewController = [[TaskDetailsViewController alloc] initWithNibName:#"TaskDetailsViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
If you need to apply navigation from a view controller, that view controller should be a part of the navigation viewcontroller stack.
So what you have to do is instead of adding the rootViewController directly, You create a navigation controller, and set the rootViewcontroller to it(as rootViewController property). Once you set it, You can add navigation controller in place of rootViewController added previously.
Then on click you can use.
[self.navigationController push..... animated:..];
You can check it. If try to access the navigationController by self.navigationController currently it would be returning nil.

Quickly returning to RootViewController

Is there any way to quickly go to rootViewController? I want to remove all views from the stack & return to rootViewController without even bothering the sequence of views on top of it.
From the docs:
popToRootViewControllerAnimated:
Pops all the view controllers on the stack except the root view controller >and updates the display.
- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated
Parameters
animated:
Set this value to YES to animate the transition. Pass NO if you are setting >up a navigation controller before its view is displayed.
Return Value:
An array of view controllers that are popped from the stack.
First I think you need to dismiss presented model then you can pop all the pushed view controllers. As presented model would not be in the stack of the navigation.
[self dismissModalViewControllerAnimated:YES];
Then you can pop to base view controller.
[self.navigationController popToRootViewController:YES];
Try this:-
[self.viewController popToRootViewController:YES];

iPhone - change navigation controller's view, using a button in a subview

I have a navigation controller with a rootview.
The rootview contains buttons, which push new views onto the navigation controller correctly.
However, on this rootview, I also have subview (it's a scrolling preview like the appStore images, view made of 3 UIview items). On these UIViews, there is a button which I'd like to change the rootview navigation controller, like the other buttons.
At the moment, it builds and runs, but the new view is not pushed. Any ideas?
Click method on on the ScrollItem button:
MyViewController *newView = [[MyViewController alloc] initWithNibName:#"ManageMyPain" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];
... i guess it is because, self doesn't have a navigation controller, but the rootview does.
Thanks!!
The property "navigationController" is only being set in a view controller if he's pushed to the navigation controllers stack. your second view is a sub view of a push viewcontroller which means this property is NULL and will not do anything if you try pushing things to it.
Yes, it is because self.navigationController will be nil if you didn't push that controller on navigations stack or if you didn't set it manually.
So you just need to have reference to rootViewController.navigationController and then [navigationController pushViewController:newView animated:YES]; will work perfectly.

how to pop a controller off the navigation stack without using the navigation bar

I'm trying to implement a navigation controller with some hierarchical views. I want to use a regular UIViewController to present choices for drilling down, I don't want to use the navigation bar - I want to have my own, custom buttons for returning back up a level.
I see examples like:
[[self navigationController] pushViewController:nextViewController animated:YES];
and my questions are these: Is navigationController a property of all UIViewControllers? Can I refer to self.navigationController regardless of the view that's on the stack? If I'm at an arbitrary view, can I have a button action that contains something like [self.navigationController popToRootViewController animated:YES];
Each view I present will need a button to return to the previous view, or to the root view, depending on the situation. I want to create that button in each view controller and control which view in the stack it returns to. Am I on the right track?
Is navigationController a property of all UIViewControllers?
Yes.
Can I refer to self.navigationController regardless of the view that's on the stack?
Every UIViewController on the UINavigationController's stack will return the UINavigationController object when calling navigationController on it.
If I'm at an arbitrary view, can I have a button action that contains something like [self.navigationController popToRootViewControllerAnimated:YES];
Yes. popToRootViewControllerAnimated: will take the user to the root UIViewController for the UINavigationController, and you can use [self.navigationController popViewControllerAnimated:YES]; to just pop off the top UIViewController. This last one does the same as tapping the Back UIBarButtonItem.
Am I on the right track?
Yes :)

How to remove all the view along with rootView from UINavigationController in iPhone

I have an UIView added in the main window with a controller. On clik of a button on this view I want to load a UINavigationController which will migrate to multiple views pushing them one by one on stack. Now what I want to do is when user reaches at the end of views, in the last view I have a done button. ON clik of this button I want to move back to my first screen unloading the NavigationController from the memory.
What is the best way to do it since popToRootViewController takes you to the first screen of UINavigationController which is my second screen.
You basically want to remove the navigation controllers view, so why cant you just say [navigationController.view removeFromSuperView] ?
One way to do this is to present the navigation controller as a modal view controller, and dismiss it when you're done:
// In the parent controller, when the navigation controller is about to appear:
UINavigationController* navController = [[UINavigationController alloc] init];
[self presentModalViewController:navController animated:YES];
// ... later, in the nav controller, when it's done being used:
[self.parentViewController dismissModalViewControllerAnimated:YES];
[self autorelease]; // goodbye, cruel world (when the ar pool is drained)
A few ideas, in order of desirability
make Controller #1 the root view controller of the stack and then use popToRootViewController. Is there a good reason why you aren't doing this already? Keep in mind you can easily hide the navigation bar from any controller, if that's what you're afraid of.
Add a method called "destroyNavigationStack" or something to main Controller #1 and have a reference to controller #1 in your app delegate. In your Nth view controller, when "done" is hit, get a reference to your app delegate (UIApplication's sharedApplication method), and send View Controller #1 this "destroy" message. There really is no reason to even think about popping view controllers off of the stack since you just want to get rid of the entire stack anyway.
Make ViewController #1 a singleton and call destroyNavigationStack