iOS 如何隐藏先前的子视图

发布于 2024-10-12 21:00:35 字数 884 浏览 4 评论 0原文

我遇到一种情况,我正在应用程序中执行一些初始化。首次启动时,我必须提交带有“我同意/我不同意”按钮选择的 EULA。当选择“我同意”时,我会显示一个模式视图,提示输入用户名和密码。这一切都很好。问题是,在验证用户名和密码后,模态视图将被关闭。我留下的 EULA 视图仍然显示在屏幕上,而不是应用程序的基本表视图。我在 EULA 视图控制器代码中执行以下操作:

- (IBAction)didAgree:(id)sender {
    LoginViewController *lvc=[[[LoginViewController alloc] init] autorelease];
    lvc.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:lvc animated:YES];
    [self.view removeFromSuperview];
}

如果我将最后一行 (removeFromSuperview) 移至 PresentModal 调用之前,那么当然,登录视图不会显示。

在登录视图控制器代码中,按下登录按钮后,我会看到以下内容:

[[self parentViewController] dismissModalViewControllerAnimated:YES];
[[self parentViewController].view removeFromSuperview];

如果我使用此代码运行,模式视图会消失,表格视图会短暂出现,然后消失,最终用户许可协议视图仍保留在屏幕上。如果我注释掉第二条语句,那么我永远不会看到表视图。

我知道我错过了一些非常明显的东西,但我不知所措,并且已经坚持了很长一段时间。

I have a situation where I am performing some initialization in an App. Upon first startup I have to present an EULA with an I Agree/I Don't Agree button selection. When the I Agree selection is made I display a modal view which prompts for a username and password. This all works fine. The problem is that after the username and password are verified and the modal view is dismissed. I am left with the EULA view still being displayed on the screen rather than the base table view of the App. I do the following in the EULA viewcontroller code:

- (IBAction)didAgree:(id)sender {
    LoginViewController *lvc=[[[LoginViewController alloc] init] autorelease];
    lvc.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:lvc animated:YES];
    [self.view removeFromSuperview];
}

If I move the last line (removeFromSuperview) to before the presentModal call then, of course, the Login view does not display.

In the login view controller code I have this after the login button is pressed:

[[self parentViewController] dismissModalViewControllerAnimated:YES];
[[self parentViewController].view removeFromSuperview];

If I run with this code, the modal view disappears and the table view appears briefly before disappearing with the EULA view remaining on the screen. If I comment out the second statement, then I never see the table view.

I know this I am missing something incredibly obvious but I am at a loss and have been stuck on this for quite a while.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢望 2024-10-19 21:00:35

我认为问题出在这里:

[self presentModalViewController:lvc animated:YES];

主要是那里的self。这意味着您以 self 的形式呈现登录屏幕:您的 EULA-ViewController。您现在无法删除 EULA 屏幕。

我建议首先显示登录屏幕,可能全部显示为灰色或根本不显示任何内容,然后以模态方式显示 EULA。

I think the problem is here:

[self presentModalViewController:lvc animated:YES];

Mainly the self there. This means that you present the login screen modally from what self is: your EULA-ViewController. You can't remove the EULA screen now.

I suggest presenting the login screen first, maybe either all grayed out or not showing anything at all, and the presenting the EULA modally from it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文