开发者

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 t开发者_开发百科hink 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];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜