如何清除或重置 UINavigation 历史记录?

发布于 2024-11-03 19:14:56 字数 1074 浏览 5 评论 0原文

我有一个使用 UINavigation 的游戏设置屏幕,并且在用户选择颜色后尝试重置或清除 UINavigation。

下图可以最好地描述我的应用程序的当前流程:

Start application -> New game -> Pick character -> Pick Color -> Start game

在“选择颜色”之前,我使用 UINavigation,但是当选择颜色时,我想清除 UINavigation 历史记录。

这样做的原因是,一旦你开始游戏,你就无法返回,并且希望 UINavigation 保持干净状态,并且没有任何迹象表明你可以返回(这还包括返回到 主菜单屏幕)。

我现在的做法是这样的;

[self.navigationController popToRootViewControllerAnimated:YES];

GameDashboardVC *dashboard = [[GameDashboardVC alloc] initWithNibName:@"GameDashboardVC" bundle:nil];
dashboard.title = @"Dashboard"; 
dashboard.managedObjectContext = self.managedObjectContext;

[self.navigationController pushViewController:dashboard animated:YES];

[dashboard release];

问题是它弹出到 rootViewController 但它永远不会将仪表板推送到堆栈上。

我已经尝试过:

[self.parentViewController.navigationController pushViewController....]

我唯一没有尝试过的是将仪表板推送放入根视图控制器本身,但我很担心,因为我不确定它是否应该在那里。

因此,放置此类功能的正确位置在哪里,以及如何清除 UINavigation 的堆栈。

感谢您的时间/帮助。

I have a game setup screen which uses UINavigation and am trying to reset or clear the UINavigation once a person has selected a color.

My app's current process can be best described in the following diagram:

Start application -> New game -> Pick character -> Pick Color -> Start game

Up until "Pick Color" I use the UINavigation, however when a color is picked I want to clear the UINavigation history.

The reason for doing this is so that you can't go back once you've started the game and want the UINavigation to with a clean slate with no indication that you can go back (and this also includes going back to the main menu screen).

The way I am doing it right now is thusly;

[self.navigationController popToRootViewControllerAnimated:YES];

GameDashboardVC *dashboard = [[GameDashboardVC alloc] initWithNibName:@"GameDashboardVC" bundle:nil];
dashboard.title = @"Dashboard"; 
dashboard.managedObjectContext = self.managedObjectContext;

[self.navigationController pushViewController:dashboard animated:YES];

[dashboard release];

The problem is that it pops to the rootViewController but it never pushes the dashboard onto the stack.

I've tried:

[self.parentViewController.navigationController pushViewController....]

The only thing I haven't tried is putting my dashboard push inside the root view controller itself, but I am concerned because I am not sure if it should even be there.

Therefore, where is the correct place to put this kind of functionality, and how do I clear the UINavigation's stack.

Thank you for your time/help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

享受孤独 2024-11-10 19:14:56

现在我满意地解决了这个问题。

我将以下代码放入 initWithNibName 方法中:

self.navigationItem.hidesBackButton = YES;

这隐藏了后退按钮,我不必弹出任何内容,但我认为出于内存原因,保留从堆栈中删除不需要的项目的想法可能会很有用。

但现在以上就可以了。

I solved the problem now to my satisfaction.

I put the following code inside my initWithNibName method:

self.navigationItem.hidesBackButton = YES;

This hid the back button and I didn't have to pop anything, but I think for memory reasons it might be useful to keep the idea of removing un-necessary items from the stack.

But for now the above will do.

坚持沉默 2024-11-10 19:14:56

如果要重置 UINavigation 历史记录,请重新初始化导航控制器。

如果您使用 AppDelegate 类中的 UINavigationController 。您可以重新初始化导航历史记录。

appDelegate.navigationController=[[UINavigationController alloc]init];

上面的代码将重置 navigationController 历史记录。

If you want reset the UINavigation History, reinitialise the navigation controller.

if you using UINavigationController from AppDelegate class. You can reinitialise the navigation history.

appDelegate.navigationController=[[UINavigationController alloc]init];

Above code will reset the navigationController history..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文