如何从实现 UITabBarController 的模态视图推送到新的视图控制器

发布于 2024-09-24 06:58:49 字数 1156 浏览 5 评论 0原文

视图以模态方式呈现:

[self presentModalViewController:modalNavController animated:YES];

该视图使用具有 4 个元素的 UITabBarController。其中一个元素“信息”有一个按钮,仅在可用时才可见。如果单击按钮,它需要推送到另一个视图控制器,但我还想从其父视图中维护选项卡栏。我无法弄清楚如何在保留或不保留标签栏的情况下执行此操作。我尝试过在所有我能想象到的地方推动和呈现模式。这应该如何正确完成?

创建标签栏:

    infoController.title = @"Info";
    streetViewController.title = @"Street View";
    reviewController.title = @"Reviews";

    streetViewController.tabBarItem.image = [UIImage imageNamed:@"flag.png"];
    infoController.tabBarItem.image = [UIImage imageNamed:@"openMarker.png"];
    reviewController.tabBarItem.image = [UIImage imageNamed:@"reviews.png"];


UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.view.frame = CGRectMake(0, 0, 320, 460);

    UINavigationController *infoNC = [[[UINavigationController alloc] initWithRootViewController:infoController] autorelease];
    infoNC.navigationBarHidden = YES;


[tabBarController setViewControllers:
    [NSArray arrayWithObjects:infoNC, streetViewController, reviewController, nil]];


[self.view addSubview:tabBarController.view];

A view is presented modally:

[self presentModalViewController:modalNavController animated:YES];

This view uses a UITabBarController with 4 elements. One of these elements, "Info" has a button that's only visible if its available. If the button is clicked, it needs to push to another view controller, but I'd also like to maintain the tab bar from it's parent view. I haven't been able to figure out how to do this with or without keeping the tab bar. Ive tried pushing and presentingModally in all the places that I could image. How should this be done properly?

Creating tab bar:

    infoController.title = @"Info";
    streetViewController.title = @"Street View";
    reviewController.title = @"Reviews";

    streetViewController.tabBarItem.image = [UIImage imageNamed:@"flag.png"];
    infoController.tabBarItem.image = [UIImage imageNamed:@"openMarker.png"];
    reviewController.tabBarItem.image = [UIImage imageNamed:@"reviews.png"];


UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.view.frame = CGRectMake(0, 0, 320, 460);

    UINavigationController *infoNC = [[[UINavigationController alloc] initWithRootViewController:infoController] autorelease];
    infoNC.navigationBarHidden = YES;


[tabBarController setViewControllers:
    [NSArray arrayWithObjects:infoNC, streetViewController, reviewController, nil]];


[self.view addSubview:tabBarController.view];

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

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

发布评论

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

评论(1

遗忘曾经 2024-10-01 06:58:49

当您将视图控制器添加到选项卡栏控制器时,您需要执行以下操作:

MyCustomViewController *vc1 = [[MyCustomViewController alloc] initWithNibName:nil bundles:nil];
UINavigationController *nc1 = [[[UINavigationController alloc] initWithRootViewController:recipesRootView] autorelease];
[vc1 release];

然后添加 nc1 而不是您的自定义视图。

然后在MyCustomViewControllerpush另一个视图控制器执行以下操作:

[self.navigationController pushViewController:(UIViewController *)page animated:YES];

这应该适合您,并保留选项卡栏控制器。

When you add the view controllers to the tab bar controller you need to do this:

MyCustomViewController *vc1 = [[MyCustomViewController alloc] initWithNibName:nil bundles:nil];
UINavigationController *nc1 = [[[UINavigationController alloc] initWithRootViewController:recipesRootView] autorelease];
[vc1 release];

then add nc1 instead of your custom view.

Then in MyCustomViewController to push another view controller do:

[self.navigationController pushViewController:(UIViewController *)page animated:YES];

That should work for you, and keep the tab bar controller.

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