当用户在选项卡栏应用程序中单击返回时,如何重置 uinavigationview 以显示根控制器

发布于 2024-08-23 04:05:50 字数 199 浏览 5 评论 0原文

当用户在选项卡栏应用程序中单击返回时,如何重置 uinavigationview 以显示根控制器

嘿,

只是想知道我会如何做到这一点。我的委托中有导航控制器以及选项卡栏控制器,每当用户单击另一个选项卡时,如果用户单击返回包含 uinavcontroller 的选项卡,我希望显示导航控制器上的根视图。

这有道理吗?

缺口

How to reset a uinavigationview to display the root controller when user clicks back to it in a tab bar app

Hey,

Just wondering how I would do this. I have the navcontroller in my delegate along with the tabbar controller and Any time the user clicks to another tab I want the rootview on the navigation controller to be shown if and when they click back the the tab that contains the uinavcontroller.

Does this make sense?

Nick

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

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

发布评论

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

评论(3

情独悲 2024-08-30 04:05:50

[self.navigationController popToRootViewControllerAnimated:YES];

或者如果您不想让它动画化,则选择“否”。

这样,所有缓存的视图仍然存在,即您不会“删除/释放”根视图之上的所有视图,除非 navigationController 认为有必要。

我希望这就是您正在寻找的..

[self.navigationController popToRootViewControllerAnimated:YES];

Or NO if you don't want it to animate.

This way all the views that were cached are still there, i.e. you don't "remove/release" all the views above the root view, unless the navigationController deems it necessary.

I hope this was what You were looking for..

奶茶白久 2024-08-30 04:05:50

将代码放在appdelegate.m中

if ([viewController isKindOfClass:[UINavigationController class]]) {
    UINavigationController *nav = (UINavigationController *)viewController;
    [nav popToRootViewControllerAnimated:NO];
}

place the code in appdelegate.m

if ([viewController isKindOfClass:[UINavigationController class]]) {
    UINavigationController *nav = (UINavigationController *)viewController;
    [nav popToRootViewControllerAnimated:NO];
}
浅语花开 2024-08-30 04:05:50

使用 UITabBar 委托方法时,必须延迟 popToRootViewControllerAnimated 调用。

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if ([self.selectedViewController isKindOfClass:[UINavigationController class]]) {
    UINavigationController *view=(UINavigationController *)self.selectedViewController;
    [view performSelector:@selector(popToRootViewControllerAnimated:) withObject:nil    afterDelay:.5];
}
}

When using the UITabBar delegate method, you must delay the popToRootViewControllerAnimated call.

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if ([self.selectedViewController isKindOfClass:[UINavigationController class]]) {
    UINavigationController *view=(UINavigationController *)self.selectedViewController;
    [view performSelector:@selector(popToRootViewControllerAnimated:) withObject:nil    afterDelay:.5];
}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文