简体   繁体   English

无法推送 viewController,因为 navigationController 为零

[英]Can't push viewController because navigationController is nil

I can't perform a transition between viewControllers because navigationController is nil .我无法在viewControllers之间执行转换,因为navigationControllernil 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 .storyboardviewController嵌入在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 ,我有一个嵌入在navigationControllerviewController ,我想从那里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.

相关问题 由于self.navigationController为nil,因此无法推送 - Can't push because self.navigationController is nil 当按下viewcontroller时,navigationController为nil - navigationController is nil,when push the viewcontroller 推送ViewController时清除navigationController堆栈 - Clear navigationController stack when push ViewController 从侧面菜单中在NavigationController中推送ViewController - Push ViewController in NavigationController from side menu 如何从ViewController选择(推送)到NavigationController中嵌入的另一个ViewController? - How to segue (push) from ViewController to another ViewController embedded in NavigationController? 我无法通过self.window上的navigationController推送loginViewcontroller - I can't push the loginViewcontroller with navigationController on self.window 在UISplitViewController中,无法使showDetailViewController:sender:push into detail navigationController - In UISplitViewController, can't make showDetailViewController:sender: push onto detail navigationController self.navigationController是nil第二次加载ViewController - self.navigationController is nil second time ViewController is loaded navigationController规则不适用于ViewController - navigationController rules doesn't work on ViewController 如何设置NavigationController的根viewController - How can i set root viewController of NavigationController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM