无法推送 viewController 因为 navigationController 为 nil

Can't push viewController because navigationController is nil

我无法在 viewControllers 之间执行转换,因为 navigationControllernil。我在 class 的不同部分记录了 navigationController 但它 returns 无处不在。在 storyboard 中,viewController 嵌入在 navigationController 中。我已经检查了 SO 上有相同问题的其他线程,但是 none 的答案对我有帮助,甚至对我来说真的很有意义。

Can't push because self.navigationController is nil

为什么是零?我该如何解决这个问题?还返回一条错误消息:

我都尝试过使用 segue:

 [self.navigationController performSegueWithIdentifier:@"experienceDetails" sender:self];

以及推送:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Inspiration" bundle:nil];
ExperienceViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"experience"];            
[self.navigationController pushViewController:viewController animated:NO];          

使用 push 没有任何反应,但会生成一条错误消息:

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior

我也在寻找解决该错误的方法,但似乎没有明确具体的解决方法。同样,我阅读并尝试过的那些建议没有用。

我真的很茫然。这么简单的事情,但我什至不明白的事情阻碍了我。

编辑 如果有帮助,我有一个 tab bar,在一个 item 中,我有一个 viewController 嵌入在 navigationController 中,我想从那里 push 到同一个 storyboard.

中的另一个 viewController

编辑 我让这个工作:

 [self showViewController:viewController sender:self];

很有可能因为它不使用 navigationController。虽然它显示为 modular,但它不是导航堆栈的一部分,这不是我想要的。很高兴知道如果 navigationController 不是零,事情就会起作用。

当从导航控制器创建 segue experienceDetails 时,我重现了所描述的行为...这是解决方案

1) 删除了 segue experienceDetails 表单导航控制器

2) 创建了 push 带有标识符 experienceDetails 的 segue,从包含的视图控制器到详细视图控制器

3) 在视图控制器中从 self 执行 segue,如下所示

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