在 ModalViewController 中呈现 ModalViewController

发布于 2024-12-01 03:53:43 字数 730 浏览 0 评论 0原文

我有一个视图,它显示为模态视图控制器,它接受用户名和密码凭据。我希望此视图检查委托,如果用户之前没有为应用程序设置解锁引脚,则将更改引脚视图显示为模式视图控制器。这是我的代码...

+(void)presentCredentialsViewController:(UIViewController *)vc{
    CredentialsViewController *cvc = [[CredentialsViewController alloc] init];
    [vc presentModalViewController:cvc animated:FALSE];
}

然后在 CredentialsViewController 中

-(void)viewDidLoad{
    [super viewDidLoad];
    if([appDelegate.pin isEqualToString: @""]){
        UserPrefsViewController *upvc = [[UserPrefsViewController alloc] init];
        upvc.cancelButton.hidden = true;
        [self presentModalViewController:upvc animated:FALSE];
    }
}

但由于某种原因它不起作用。调试器单步执行代码,不会出现错误,但第二个模式视图控制器不会显示。

I have a view which is presented as a modal view controller which takes username and password credentials. I want this view to check the delegate, and if the user hasn't previously set an unlock pin for the app, to then show the change pin view as a modal view controller. This is my code...

+(void)presentCredentialsViewController:(UIViewController *)vc{
    CredentialsViewController *cvc = [[CredentialsViewController alloc] init];
    [vc presentModalViewController:cvc animated:FALSE];
}

and then in CredentialsViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    if([appDelegate.pin isEqualToString: @""]){
        UserPrefsViewController *upvc = [[UserPrefsViewController alloc] init];
        upvc.cancelButton.hidden = true;
        [self presentModalViewController:upvc animated:FALSE];
    }
}

But for some reason it doesn't work. The debugger steps through the code without error, never the less, the second modal view controller isn't displayed.

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

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

发布评论

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

评论(2

首先,我建议检查您的 appDelegate.pin 是否为空而不是 nil。如果它为零,则 if 语句将不被满足,并且您的第二个 ModalView 将不会呈现。

您可能还想尝试之前的建议,从 viewDidAppear 调用 presentModalViewController,或者如果将其保留在 viewDidLoad 中,则设置延迟。当 CredentialsViewController 尚未呈现时,它可能会尝试呈现第二个视图。

First, I would suggest checking that your appDelegate.pin is blank and not nil. If it is nil, the if statement would not be satisfied and your second ModalView would not be presented.

You may also want to try the previous suggestion, calling presentModalViewController from viewDidAppear, or setting a delay if leaving it in viewDidLoad. It is possible that the CredentialsViewController is trying to present the second view when it has not yet presented itself.

情释 2024-12-08 03:53:43

if 语句被命中,第二个 PresentModalViewController 正在执行,没有错误,但它只是没有显示。我确实尝试将代码放入 ViewDidAppear 以及其他一些地方,例如 applicationWillBecomeActive 等。虽然实际上并没有使代码崩溃,但这些方法仍然不会显示视图控制器。最后我选择了这个:

start with pin of @""
on applicationDidEnterBackground check if pin has been set
if yes
PresentModalViewController: PinViewController
if no
do nothing

有点黑客,但现在就可以了。我想我应该在某个地方放置某种通知,警告该引脚尚未设置。我想关于延迟的建议可能会奏效。我将来可能会尝试一下。谢谢各位……加分!

The if statement is being hit and the second PresentModalViewController is executing without error, but it just wasn't displaying. I did try putting the code in ViewDidAppear and a load of other places as well, such as applicationWillBecomeActive etc. Although not actually crashing the code, still none of these approaches would show the view controller. In the end I have opted for this:

start with pin of @""
on applicationDidEnterBackground check if pin has been set
if yes
PresentModalViewController: PinViewController
if no
do nothing

Bit of a hack but it will do for now. I suppose I should put some sort of notification in somewhere warning that the pin hasn't been set. The suggestion about the delay may possibly work I suppose. I might give it a go in the future. Thanks guys....points up!

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