Reputation: 19418
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...
Upvotes: 1
Views: 750
Reputation: 5765
I think you should push the Forgot password & Register VCs also as modal controllers. Have you tried that?
Upvotes: 4
Reputation: 1230
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];
Upvotes: 0
Reputation: 11314
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.
Upvotes: 0
Reputation: 12714
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];
Upvotes: 5