gpt4 book ai didi

ios - 单击按钮删除 View Controller

转载 作者:行者123 更新时间:2023-11-29 03:35:41 25 4
gpt4 key购买 nike

我正在为 iOS 应用程序开发一个库,该库将根据用户输入的凭据对用户进行身份验证。

我正在做的是,从 View Controller 说 TestViewController 我在 TestViewController 之上设置一个新的 View Controller LoginScreenViewController ,当用户使用以下代码点击按钮。

LoginScreenViewController * LoginScreen = [[LoginScreenViewController alloc] initWithNibName:nil bundle:nil];

[self.view addSubview:LoginScreen.view];

LoginScreenViewController包含一个Cancel按钮,我想删除该LoginScreenViewController按钮。为此,我使用以下代码

[self.view removeFromSuperview];

问题是当我执行此代码时,我的应用程序崩溃了。

由于我的 LoginScreenViewController 是由库定义的,因此我希望它独立于调用者的实现。

编辑:
LoginScreenViewController.m 中,我使用以下代码将事件处理程序添加到取消按钮。

[button addTarget:self action:@selector(CancelButtonHandler:) forControlEvents:UIControlEventTouchUpInside];

当我点击取消按钮时,应用程序崩溃了。即使 CancelButtonHandler 不包含任何代码行。

最佳答案

您正在尝试删除错误的 View 。要删除 LoginScreen View ,请执行以下操作:

[LoginScreen.view removeFromSuperview];

关于ios - 单击按钮删除 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19223606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com