ios导航堆栈操作 [英] ios navigation Stack Manipulation

查看:155
本文介绍了ios导航堆栈操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题尝试从ios应用程序操纵导航堆栈。或者至少是由于该操作导致的行为。

i am having issues try to manipulate the navigationstack from an ios app. Or at least with the behaviour as a result of that manipulation.

我的情况:

我有3个ViewControllers 。

i have 3 ViewControllers.

控制器a显示多个级别,
控制器b是游戏视图
控制器c是某种分数

Controller a shows multiple levels, Controller b is the gameview Controller c is some sort of Score

显然,我将在控制器a中选择一个级别,一旦级别完成,就会触发到控制器b的segue到控制器c。每个segue作为推动。

Obviously i will select a level in controller a, which triggers a segue to controller b, once the level is finished ill segue to controller c. every segue as a push.

现在一旦进入控制器c我不想使用后退按钮回到b。我想回到控制器a。为了使其工作,我从堆栈中删除了控制器,所以后面不会移动到控制器b。这样可以正常工作。

Now once im in controller c i dont want to be able to go back to b using the back button. I want to move back to controller a. In order for this to work, i removed the controller from the stack, so back wont move to controller b. This works fine.

我面临的问题是后退按钮确实显示在控制器a上,这似乎是关闭的,因为不应该有任何后退。如果我点击后退按钮,应用程序不会崩溃,按钮只会消失而留下标题。

The issue im facing is that the backbutton does show on controller a, which seems off since there shouldn't be any back. If i click the backbutton, the app doesnt crash, the button just disappears leaving the title.

我尝试添加:

    NSArray* controllers = [self.navigationController viewControllers];

    if ([controllers count]<=1) {
        [self.navigationItem setHidesBackButton:YES animated:YES];
    } else {
        [self.navigationItem setHidesBackButton:NO animated:YES];
    }
    [super viewDidAppear:animated];

如某些相对stackoverflow文章所述,但没有成功。除了这个不起作用之外,似乎ios从Storyboard创建了那些按钮而没有我实际添加它们,但是当它们不再需要时它们不会删除它们。这给我留下了一些选择。

as suggested in some relative stackoverflow article, without success. Besides this not working it seems off that ios creates those buttons from Storyboard without me actually adding them, but doesnt remove them when they arent necessary anymore. This leaves me with some options.


  • 我认为ios比实际更聪明

  • 我遗漏了更新导航栏必不可少的东西

  • 我犯了这么大错误

besdies即时通讯使用此代码剪切从控制器b转换为c。

besdies im using this code snipped to segue from Controller b to c.

[self performSegueWithIdentifier:@"feedbackSegue" sender:self];
[self removeFromParentViewController];

非常感谢任何关于失踪操作或一般不良行为的提示。

Any hints concerning missing operations or general bad practice is greatly appreciated.

更新

经过进一步调查后,它不仅仅是后退按钮,而是关闭整个导航栏。它表现得好像被移除的控制器仍在那里。 BackButton在那里,另一个uiActionButton在右端。

After further investigation, its not just the back button, its the whole navigationbar that is off. it behaves as if the removed controller was still there. The BackButton is there and another uiActionButton on the right end.

导航栏是否将状态存储在不同的堆栈上,而不是视图控制器?如果是这种情况,我也可以从这个堆栈中删除该状态,以保持一致。

Does the navigationbar store its states onto a different stack, than the viewcontroller one? if this was the case, i could remove that state from this stack as well, to keep it consistent.

推荐答案

你可以试试这在您的视图控制器中。这将删除以前的视图控制器,在您的情况下为b。您还必须将b保留在堆栈中(删除行[self removeFromParentViewController]';)

You could try this in your view controller c. This will remove the previous view controller, in your case the b. You'd also have to keep b in your stack (remove the line [self removeFromParentViewController]'; )

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    if(self.navigationController.viewControllers.count>2){
        NSArray *controllers = self.navigationController.viewControllers;
        NSMutableArray *newViewControllers = [NSMutableArray arrayWithArray:controllers];
        [newViewControllers removeObject:[controllers objectAtIndex:self.navigationController.viewControllers.count - 2]];
        self.navigationController.viewControllers = newViewControllers;
    }
}

这篇关于ios导航堆栈操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆