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];
Related
I am developing an e-com app for iPhone in which i need to open a view immediately when the user clicks on a button for the upcoming view, the data loads large images from server , to load images I am using a background thread .
Thank You
Simple, here's how to create a UIViewController and present it from within an IBAction.
- (IBAction)goToNextView:(id)sender
{
//if you are using xibs use this line
UIViewController *controller = [[UIViewController alloc] initWithNibName:#"myXib" bundle:[NSBundle mainBundle]];
//if you are using storyboards use this line
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"myViewControllersID"];
//to present the controller modally use this
[self presentViewController:controller animated:NO completion:nil];
//or if you are pushing to this controller using a navigation controller use this
[self.navigationController pushViewController:controller animated:NO];
}
Be sure to pass animated NO so that the view is displayed immediately.
You need to make a button and then add its action like
-(IBAction)ButtonAction:(id)sender{
CalController *calculateView=[[CalController alloc] initWithNibName:#"CalController" bundle:nil];
[self.navigationController presentModalViewController:calculateView animated:NO];
}
You can use modal view controller for this
- (IBAction)showController:(id)sender {
SampleViewController *sampleView = [[SampleViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}
Here it is the tutorial http://timneill.net/2010/09/modal-view-controller-example-part-1/
I am trying to navigate from one page to another on a button click in a facebook appliaction.
I am using
registerUser=[[RegisterPage alloc]initWithNibName:#"RegisterPage" bundle:nil];
[self presentModalViewController :registerUser animated:YES];
for presenting the next view after getting response from facebook.
But it is not showing the next view. It works fine in all other places where I used to present other views.
Anyone have idea about this issue?
What exactly is 'self' here? Is it a viewcontroller? Or just a UIView?
I think this'll only work if self is a viewcontroller or some subclass of it.
My code to present a view controller is somewhat like yours (without a nib):
ViewController *controller = [[ViewController alloc] initWithNibName:nil bundle:nil];
[controller setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:controller animated:YES];
[controller release];
And to present a navigation controller it's like this (without a nib):
ViewController *controller = [[ViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[navController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:navController animated:YES];
[navController release];
[controller release];
Sometimes simply copying someones code helps.
thanks for everyones reply.i have solved it after a long fight.i just dismissed the view before pesenting the next view and set dismissmodalviewcontrollerAnimated to NO.[self dismissModalViewControllerAnimated:NO];
nextview = [[LoginPage alloc]initWithNibName:#"LoginPage" bundle:nil];
[self presentModalViewController: nextview animated:YES];hope this help someone like me
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];
I have a main window that pops a modal view controller. When done in this modal view controller, it returns to the main window then dismisses itself.
Then the main windows pops a new Modal view controller with animated=YES.
The problem is that the dismiss call that is done inside the first modalviewcontroller applies to both and SecondController is never shown.
Putting the first dismiss before or after the parent call does not change anything.
If first dismiss is set wih animate= NO, everything works fine. But I need the animation.
Main.m
- (void) entry {
FirstController *nextWindow = [[FirstController alloc] initWithNibName:#"theNIB" bundle:nil];
nextWindow.caller = self;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
[self.navigationController presentModalViewController:navController animated:YES];
[nextWindow release];
[navController release];
}
- (void) thingsDoneInFirstModalController:(OBJECT)returnValue retval2:(OBJECT2)returnValue2 {
[self display2ndController];
}
- (void) display2ndController {
SecondController *nextWindow;
nextWindow = [[SecondController alloc] initWithNibName:#"NIB2" bundle:nil];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextWindow];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[nextWindow release];
}
1st ModalViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController dismissModalViewControllerAnimated:YES];
[self.caller thingsDoneInFirstModalController:theResult retval2:someMoreResult];
}
What may I do ?
I don't want to catch anything in view....Disapear...
Why does the dismiss colides as they are not called from the same navigation controller ?
The reason is likely the animation when you dismiss it. Try showing the second modal window using the performSelector:withObject:afterDelay:, a method inherited from NSObject. Reference here.
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];