ewDidLoad中没有执行SegueWithIdentifie

ewDidLoad中没有执行SegueWithIdentifie

本文介绍了为什么在viewDidLoad中没有执行SegueWithIdentifier工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦在视图控制器上调用viewDidLoad,我就试图触发故事板segue。 segue附加了一个标识符,当从链接到按钮或其他控件的方法内部调用时,它可以正常工作。但它在viewDidLoad中不起作用。它只是默默地失败了。在viewDidLoad中是否有一些关于segue被忽略的规则?

I'm trying to trigger a storyboard segue as soon as viewDidLoad is called on a view controller. The segue has an identifier attached, and works fine when called from inside a method thats linked to a button or other control. But it doesn't work inside of viewDidLoad. It just silently fails. Is there some rule about segue's being ignored in viewDidLoad?

我试过这两个:

[self performSegueWithIdentifier: @"mySegue"
                          sender: self];

这个:

[self dismissViewControllerAnimated:YES completion:^() {
[self performSegueWithIdentifier:@"mySegue" sender:self];
}];

两者均无效。

推荐答案

您无法关闭尚未显示的视图控制器。 didLoad 具有纯粹的内存管理功能,您可以将其用作(部分)构造函数。
可能有效的方法是在 viewDidAppear 中启动一个segue,但是我建议你在第一时间开始使用你想要的视图。

You can not dismiss a view controller that isn't presented yet. didLoad has purely memory management functions, you can use it as (part of a) constructor.What may work, is to start a segue in viewDidAppear, however I would suggest to start with the view you want at the first time.

这篇关于为什么在viewDidLoad中没有执行SegueWithIdentifier工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:01