[英]Can't push viewController because navigationController is nil
I can't perform a transition between viewControllers
because navigationController
is nil
.我无法在
viewControllers
之间执行转换,因为navigationController
是nil
。 I have logged navigationController
in different parts of the class
but it returns nil everywhere.我在
class
不同部分记录了navigationController
,但它在任何地方都返回 nil。 In storyboard
the viewController
is embedded in a navigationController
.在
storyboard
, viewController
嵌入在navigationController
。 I have checked other threads on SO
with the same issue, but none of the answer has helped or even really made sense to me.我已经用同样的问题检查了
SO
上的其他线程,但没有一个答案对我有帮助,甚至对我来说都没有意义。
Can't push because self.navigationController is nil 无法推送,因为 self.navigationController 为零
navigationController is nil,when push the viewcontroller 导航控制器为零,当推送视图控制器时
Why is it nil?为什么是零? And how do I solve this?
我该如何解决这个问题? An error message is also returned:
还会返回错误消息:
I have tried both using a segue
:我已经尝试过使用
segue
:
[self.navigationController performSegueWithIdentifier:@"experienceDetails" sender:self];
as well as pushing:以及推动:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Inspiration" bundle:nil];
ExperienceViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"experience"];
[self.navigationController pushViewController:viewController animated:NO];
Nothing happens using push
but an error message is produced:使用
push
没有任何反应,但会产生一条错误消息:
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
不允许在解除分配时尝试加载视图控制器的视图,这可能会导致未定义的行为
I have looked for solutions on that error too, but there doesn't seem to be a clear and concrete answer to how to solve it.我也一直在寻找有关该错误的解决方案,但似乎没有关于如何解决它的明确而具体的答案。 Again, those suggestions I read and tried didn't work.
同样,我阅读和尝试的那些建议没有奏效。
I'm really at a loss here.我真的很茫然。 Such a simple thing to do but I'm hindered by something I don't even understand.
这么简单的事情要做,但我什至不明白的事情阻碍了我。
EDIT If it helps, I have a tab bar
and in one item
I have the viewController
that is embedded in a navigationController
and from there I want to push
to another viewController
within the same storyboard
.编辑如果有帮助,我有一个
tab bar
,在一个item
,我有一个嵌入在navigationController
的viewController
,我想从那里push
送到同一个storyboard
另一个viewController
。
EDIT I got this to work:编辑我得到了这个工作:
[self showViewController:viewController sender:self];
very likely because it doesn't use navigationController
.很可能是因为它不使用
navigationController
。 Its presented as modular
though and is not part of the navigation stack, which is not something I want.它虽然呈现为
modular
但不是导航堆栈的一部分,这不是我想要的。 Just good to know that things would work if navigationController
wasn't nil.很高兴知道如果
navigationController
不为零,事情就会起作用。
I reproduced the described behaviour when segue experienceDetails was created from navigation controller... and here is solution我转载的时候是从导航控制器创建赛格瑞experienceDetails描述的行为...这里是解决方案
1) deleted segue experienceDetails form navigation controller 1)删除赛格瑞experienceDetails形成导航控制器
2) created push
segue with identifier experienceDetails from included view controller to detail view controller 2)从包含的视图控制器到细节视图控制器创建带有标识符experienceDetails的
push
segue
3) in view controller performed segue from self
as below 3) 在视图控制器中从
self
执行 segue 如下
[self performSegueWithIdentifier:@"experienceDetails" sender:self];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.