在 UITabBarController 中实现 Back 操作
我有一个控制器视图(MenuControllerView),里面有一个按钮,当我单击该按钮时,将出现一个新的 ViewController,其中包含以编程方式创建的 TabBarController,如下所示:
UIView* topView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
tabBarController = [[UITabBarController alloc] init];
viewController1 = [[ViewController1 alloc] init];
viewController2 = [[ViewController2 alloc] init];
viewController3 = [[ViewController3 alloc] init];
viewController4 = [[ViewController4 alloc] init];
tabBarController,viewControllers = [NSArray arrayWithObjects:viewController1 , viewController2 , viewController3 ,viewController4, nil];
[[self tabBarController] setSelectedIndex:1];
[topView addSubView:[tabBarController view]];
我不想为第一个按钮项显示 ViewController1,而是想将一个操作放回其中返回到我的 MenuViewController,但我不知道该怎么做。
谢谢
I have a controllerView (MenuControllerView) with a button inside, when I click on the button a new ViewController will appear with a TabBarController created programmatically like this:
UIView* topView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
tabBarController = [[UITabBarController alloc] init];
viewController1 = [[ViewController1 alloc] init];
viewController2 = [[ViewController2 alloc] init];
viewController3 = [[ViewController3 alloc] init];
viewController4 = [[ViewController4 alloc] init];
tabBarController,viewControllers = [NSArray arrayWithObjects:viewController1 , viewController2 , viewController3 ,viewController4, nil];
[[self tabBarController] setSelectedIndex:1];
[topView addSubView:[tabBarController view]];
Instead of displaying ViewController1 for the first button Item, I want to put an action Back in it to return to my MenuViewController, but I don't know how how to do it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否考虑过将 UITabBarController 作为模态视图控制器呈现并实现 UITabBarControllerDelegate?例如,这似乎对我有用(我使第三个选项卡返回到 MenuViewController ):
Have you considered presenting the
UITabBarController
as a modal view controller and implementing UITabBarControllerDelegate? e.g. this seems to work for me (I make the third tab return to MenuViewController here):我怀疑这种方法是不是一种好的方法。你将打破典型的 iPhone 行为,这会让用户感到困惑。 TabBarController 的设计(从功能上和技术上来说)是为了在视图之间进行切换,而 NavigationController 则用于推送和弹出视图(前进和后退)。当然,您可以将它们组合起来(这并不总是那么容易),但您不应该将 TabBar 用作 NavigationBar。
I doubt that this approach is a good one. You'll gonna break typical iPhone behaviour which will confuse users. The TabBarController is designed (functionally and technically) to change between views while a NavigationController is for pushing and popping views (go forth and back). Of course you can combine those (which is not always easy), but you shouldn't use TabBar as NavigationBar.
如果我理解正确,您可以从超级视图中删除标签栏的视图。有点像
如果您只想处理选项卡栏项目的选择,可以使用 UITabBarDelegate 协议的
tabBar:didSelectItem:
方法。if I understand right, you can just remove your tabbar's view from superview. smth like
if you just want to handle selection of tabbar item, you can use
tabBar:didSelectItem:
method of th UITabBarDelegate protocol.这就是你想做的吗?
这是在推送到子视图控制器时使用 UINavigationController 自动创建的。
Is this what you're trying to do?
This automatically created with a UINavigationController upon pushing to a child view controller.