I have a base UINavigationController
, and 3 UIViewController
.
我有一个基础UINavigationController和3 UIViewController。
Let's call them Home, VC2, and VC3
.
我们称之为Home,VC2和VC3。
I have a storyboard segue from Home
to VC2
, and from VC2
to VC3
.
我有一个故事板segue从Home到VC2,从VC2到VC3。
Now... if I call [self.navigationController popToRootViewControllerAnimated:YES]
from within VC3, I get taken back to 'Home' with the top navigationItem
bar of VC2! What!?
现在......如果我从VC3中调用[self.navigationController popToRootViewControllerAnimated:YES],我会回到带有VC2顶部navigationItem栏的'Home'!什么!?
If I simply use the "back" button, the navigationItem
top bar displays as expected for each of the views...
如果我只使用“后退”按钮,navigationItem顶栏会按预期显示每个视图...
Can anyone suggest an alternative to popToRootViewControllerAnimated:(BOOL)
, or popToViewController:(UIViewController*)
? Both cause the issue to occur..
任何人都可以建议替代popToRootViewControllerAnimated:(BOOL),或popToViewController:(UIViewController *)?两者都导致问题发生..
EDIT: Also, just to illustrate further what happens: Once I pop back to Home, the VC2's navigationItem is sitting there and it contains its own title and back button - if I hit the back button, the top bar slides off the right and now the top bar is empty. Again, this doesn't happen when using VC3:back -> VC2:back buttons to get back to Home. Seems like a rather bad thing for UIKit to be doing, but maybe I'm missing something.
编辑:此外,只是为了进一步说明会发生什么:一旦我弹回家,VC2的navigationItem就坐在那里,它包含自己的标题和后退按钮 - 如果我点击后退按钮,顶部栏向右滑动顶栏是空的。同样,使用VC3时不会发生这种情况:返回 - > VC2:返回按钮返回主页。对UIKit而言似乎是一件相当糟糕的事情,但也许我错过了一些东西。
1 个解决方案
#1
1
OK I figured out what the problem was.
好的我弄清楚问题是什么。
There was actually a different view at the bottom of the stack. I'm fixing bugs in someone else's project, so I was a little hazy on the structure.
堆栈底部实际上有一个不同的视图。我正在修复别人的项目中的错误,所以我对结构有点模糊。
So it was more like this:
所以它更像是这样的:
Splash > Home > VC2 > VC3
Splash> Home> VC2> VC3
Somehow, popToRoot from VC3 was going to Home
, rather than Splash
. And somehow, the nav bar of VC2
was appearing after that. So, inside of Home
's viewDidAppear
, I added self.navigationController.viewControllers = [NSArray arrayWithObject:self];
and the nav bar issue sorted itself out.
不知何故,来自VC3的popToRoot正在回家,而不是Splash。不知何故,VC2的导航栏出现在那之后。所以,在Home的viewDidAppear里面,我添加了self.navigationController.viewControllers = [NSArray arrayWithObject:self];导航栏问题自行解决。
#1
1
OK I figured out what the problem was.
好的我弄清楚问题是什么。
There was actually a different view at the bottom of the stack. I'm fixing bugs in someone else's project, so I was a little hazy on the structure.
堆栈底部实际上有一个不同的视图。我正在修复别人的项目中的错误,所以我对结构有点模糊。
So it was more like this:
所以它更像是这样的:
Splash > Home > VC2 > VC3
Splash> Home> VC2> VC3
Somehow, popToRoot from VC3 was going to Home
, rather than Splash
. And somehow, the nav bar of VC2
was appearing after that. So, inside of Home
's viewDidAppear
, I added self.navigationController.viewControllers = [NSArray arrayWithObject:self];
and the nav bar issue sorted itself out.
不知何故,来自VC3的popToRoot正在回家,而不是Splash。不知何故,VC2的导航栏出现在那之后。所以,在Home的viewDidAppear里面,我添加了self.navigationController.viewControllers = [NSArray arrayWithObject:self];导航栏问题自行解决。