如何从实现 UITabBarController 的模态视图推送到新的视图控制器
视图以模态方式呈现:
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您将视图控制器添加到选项卡栏控制器时,您需要执行以下操作:
然后添加 nc1 而不是您的自定义视图。
然后在
MyCustomViewController
中push
另一个视图控制器执行以下操作:这应该适合您,并保留选项卡栏控制器。
When you add the view controllers to the tab bar controller you need to do this:
then add
nc1
instead of your custom view.Then in
MyCustomViewController
topush
another view controller do:That should work for you, and keep the tab bar controller.