1

我在浏览视图时遇到问题。

我有 VC 说,Login,我是从另一个 VC 调用的,例如:

- (IBAction) btnAction 
{           Login * login = [[Login alloc] init];

        [self.navigationController pushViewController:login animated:YES];
}   

在登录 VC 中有两个按钮,Register 和 Forget Password,相应地调用另一个 VC,RegisterVC 和 ForgetPassVC。

- (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];
}

我的问题 :

当我通过一切调用登录时,[self.navigationController pushViewController:login animated:YES];一切正常。

但是在某些 VC 中,我需要将登录页面显示为[self presentModalViewController:login animated:YES];此时注册和忘记密码这两个按钮不起作用。在按钮单击时没有任何反应。

问题是什么 ?我认为我已经将登录添加为模式视图而不是 pushViewConterller ?如果是这样,那么我该如何完成这项任务?

希望问题很清楚。

谢谢...

4

4 回答 4

5

当您以模态方式呈现控制器时,它们不在导航控制器中。你应该写

UINavigationViewController *nvc = [[UINavigationViewController alloc] initWithRootViewController:login];
[login release];
[self presentModalViewController:nvc animated:YES];
[nvc release];
于 2011-08-24T11:12:22.253 回答
4

我认为您应该将忘记密码和注册 VC 也作为模态控制器推送。你试过吗?

于 2011-08-24T11:11:27.150 回答
0

当你在做 [self presentModalViewController:login animated:YES]; 在这种情况下,您的视图控制器已通过,现在当您尝试实现 [self.navigationController pushViewController:forgotPassword animated:YES]; 它没有工作,因为你没有导航控制器。

是否有必要将您的登录信息显示为模态视图。然后使用此代码:-

 - (IBAction) btnAction 
{
        Login *login=[[[Login alloc]initWithNibName:@"Login" bundle:nil]autorelease];
        UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:login]autorelease];
        [[self navigationController] presentModalViewController:navController animated:YES];

    }   

现在您的忘记和注册 btn 操作将被调用并导航到相应的页面。

于 2011-08-24T11:15:22.847 回答
0

将您的登录视图控制器作为根控制器呈现导航控制器。检查以下代码。

UINavigationController *navController = [UINavigationController alloc] initWithRootController:loginController]; [自我presentModalViewController:navController];[导航控制器发布];

于 2011-08-24T11:16:32.483 回答