presentModalViewController: how to interact with parent - iphone

Showing a modal ViewController works fine:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myView];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
In my modal view, I have a navigation button to switch back to the mainmenu. Normally a would call [self.navigationController popToViewController:delegate.viewMainmenu animated:YES]; but thats not possible inside the modal view. How can I interact with the "parent" to call him that he calls popToViewController?
Thanks a lot!

use property parentViewController in your modal vc and call
[self.parentViewController dismissModalViewControllerAnimated: YES];

If you are asking how to dismiss the modal view controller, you'll want the modal view itself to call:
[self dismissModalViewControllerAnimated:YES];

Related

Back to main view controller from modal View controller

I want to make a back button from a modal view to the Main view.
The View Controller is embedded in the navigation controller. The menu button take me to the Second View Controller. There I have a back button who works fine using this:
[self.navigationController popViewControllerAnimated:YES];
I want to go back to the Main View Controller from the Page Two VC.
I have tried:
- (IBAction)goToRootView:(id)sender {
[self.presentingViewController dismissViewControllerAnimated:(NO) completion:nil];
[self.navigationController popViewControllerAnimated:YES];
}
and:
- (IBAction)goToRootView:(id)sender {
[self dismissViewControllerAnimated:(NO) completion:nil];
[self.navigationController popViewControllerAnimated:YES];
}
The first just goes back to the Second VC, the last sends and lldb error.
How can I go from Mantras Page Two VC to Main VC?
Thank you for your help!
You can tray this...
CHS_View_Controller *oldView = [self.storyboard instantiateViewControllerWithIdentifier:#"CHS_View"];
UINavigationController *yourNavigationController = [[UINavigationController alloc] initWithRootViewController:oldView];
yourNavigationController.modalTransitionStyle= UIModalTransitionStyleCrossDissolve;
[self presentViewController:yourNavigationController animated:YES completion:nil];
for that you must:
1) import you dest controller
#import "CHS_View_Controller.h" // your controller name
and
2)
set an Identifier for your CHS_Controller, "CHS_View" in the bellow example (into the Storyboard Editor and in the Attributes Inspector)
In the first snippet, instead of
[self.navigationController popViewControllerAnimated:YES];
try
[self.navigationController popToRootViewControllerAnimated:YES];

Navigate to another view controller from a popup view

I have a table in my pop up view. But when clicking on a table row, it doesn't navigate to another view controller. Is there any direct method to navigate from popup view to another view controller ?
thanks in advance.
Code::
ProductListView1 *p = [[ProductListView1 alloc]initWithNibName:#"ProductListView1" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:p animated:YES];
Did you try [self presentViewController:p animated:YES completion:nil];
If you don't have a UINavigationController than you can't push a UIViewController.
Also note, that if you push a UIViewController in a UIPopoverController, it will just enlarge the UIPopover. If you want a whole new view to be displayed, than you must use presentViewController: and you could put a UIToolbar to a UINavigationController onto that modal view.
ContentViewController of popover, should be a navigation controller.
First create navigationController with rootViewController as tableViewController(first controller to be displayed in popover)
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
and then present navigationController in popover
[popOver setContentViewController:navigationController animated:YES];
And then you can push another controller in tableViewController's didSelectRowAtIndexPath: delegate method
ProductListView1 *p = [[ProductListView1 alloc]initWithNibName:#"ProductListView1" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:p animated:YES];

UINavigation : How to push view from presented modal view

I am having problem in navigation of views.
I have VC say, Login, which I am calling from another VC like :
- (IBAction) btnAction
{ Login * login = [[Login alloc] init];
[self.navigationController pushViewController:login animated:YES];
}
in login VC there are two buttons say, Register and Forget Password, that calls another VC, RegisterVC and ForgetPassVC accordingly.
- (IBAction) btnRegisterNow : (id) sender
{
aRegister = [[Register alloc] initWithNibName:#"Register" bundle:nil];
[self.navigationController pushViewController:aRegister animated:YES];
}
- (IBAction) btnForgotPassword : (id) sender
{
forgotPassword = [[ForgotPasswd alloc] initWithNibName:#"ForgotPasswd" bundle:nil];
[self.navigationController pushViewController:forgotPassword animated:YES];
}
My Problem :
When I call Login by [self.navigationController pushViewController:login animated:YES]; every thing works fine.
But in some VCs I need to display login page as [self presentModalViewController:login animated:YES]; At this time the two buttons, Register and Forget Password does not work. On button click nothing happens.
What is the problem ? I think bocz of I have added Login as modal view not a pushViewConterller ??? if so then how can I accomplish this task ?
hope question is clear.
Thanks...
When you present your controller modally, they aren't in a navigation controller. You should write
UINavigationViewController *nvc = [[UINavigationViewController alloc] initWithRootViewController:login];
[login release];
[self presentModalViewController:nvc animated:YES];
[nvc release];
I think you should push the Forgot password & Register VCs also as modal controllers. Have you tried that?
When you are doing
[self presentModalViewController:login animated:YES]; in this case your view controller get passed and now when you try to implement [self.navigationController pushViewController:forgotPassword animated:YES]; it did ont work because you dont have navigation controller.
Is it necessary to present your login as modal view.
Then use this code:-
- (IBAction) btnAction
{
Login *login=[[[Login alloc]initWithNibName:#"Login" bundle:nil]autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:login]autorelease];
[[self navigationController] presentModalViewController:navController animated:YES];
}
Now your forgot and register btn action will called and will navigate to the that corresponding page.
Present navigation controller with your login view controller as root controller.Check below code.
UINavigationController *navController = [UINavigationController alloc] initWithRootController:loginController];
[self presentModalViewController:navController];
[navController release];

Presented modal navigationcontroller under current navigationcontroller iphone

In my application the modal navigationcontroller that I am presenting is going under the current navigationcontroller so I'm not able to view the new navigationbar as it's disappearing under the current one.
I'm presenting the modalview on self and not self.navigationcontroller because self.navigationcontroller doesn't present the modalviewcontroller.
Also how to push a view on this modal navigationcontroller?
I'm using following code in one of my viewControllers:
fullListTopCompanies *fullListTopCompaniesInstance = [[fullListTopCompanies alloc] initWithNibName:#"fullListTopCompanies" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:fullListTopCompaniesInstance];
fullListTopCompaniesInstance.navigationController.navigationItem.title = #"F";
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[fullListTopCompaniesInstance release];
Can anybody please help?
Thanx in advance.
use animated with transition
according to me you have to change the animation style
i done it before but forgot the code i will post it when i get it
self.navigationController.navigationItem.title = #"F";
Add the above line of code in viewDidLoad method of "fullListTopCompanies" class.
Actually your navigation bar hides because of the modal view and modal view by default doesnt have Navigation bar.To add a navigation bar to modal view you can try the below code:
In Header File
IBOutlet fullListTopCompanies *fullListTopCompaniesInstance;
In Implementation File
UINavigationController *nav = [[UINavigationController alloc] initWithNibName:#"fullListTopCompanies" bundle:nil];
[self presentModalViewController:nav animated:YES];
[nav release];
Also on the "fullListTopCompanies" View Controller dont forget to put a left navigation bar button item for dismissing the modal view.
So add that left bar button (Ideally Cancel Button on navigation bar) and event handler for that left barr button should contain the code
[self dismissModalViewControllerAnimated:YES];
Hope this helps.

Viewcontroller not getting pushed to stack

I am fairly new to iPhone. I have a peculiar problem. I am adding a view controller as a subView to the current view. And then I want to push a new view controller from it. The problem is when I try to do pushViewController, it is not responding.
For example, in CurrentViewController I have added NewViewController's view as subView
[self.view addSubView : NewViewController.view]
Now From NewViewController, on the click of a button I am doing the following :
SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
Here the secondVC doesn't get pushed to the stack.
If you have used view based application, You have to use this code.
SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
// [self.navigationController pushViewController:secondVC animated:YES];
[self presentModalViewController:secondVC animated:YES];
If you want to use navigation controller in your appln. First you have to add navigation controller in your appln and then only will navigate the view.
Perhaps the problem is that method is called pushViewController not pushToViewController. Try
SecondViewController *secondVC = [SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
// don't forget release here
[secondVC release];