gpt4 book ai didi

iphone - 在 TabBarController 中的选项卡之间切换/导航

转载 作者:行者123 更新时间:2023-11-28 18:44:36 26 4
gpt4 key购买 nike

所以我的标签栏 Controller 中有 2 个标签。

我在选项卡 2 中有一个按钮,如果我单击它,控制权需要传递给选项卡 1,它应该成为当前的 View Controller 。

//I should not use navigation for this because the view would navigate
the present view to the view in tab 1 ; but the tab will still indicate Tab 2//

我只需要它在我单击按钮时转到选项卡 1。

最佳答案

当您点击按钮时,只需让它发送以下内容

self.tabBarController.selectedIndex = 0;

这将告诉它切换到其索引中的第一个选项卡 (Tab 1)

如果您想为更改添加动画,您将使用 transitionFromView:toView:duration:options:completion:。为了实现这一点,您将使用类似这样的东西:

[UIView transitionFromView:self.view 
toView:[[self.tabBarController.viewControllers objectAtIndex:0] view]
duration:1 /*or whatever time you want*/
options:/*specify your animation transition here, they are found in the UIView documentation*/
completion:(void (^)(BOOL finished))completion:^(BOOL finished) {
if (finished) {
tabBarController.selectedIndex = 0;
}
}];

选项可让您控制它的过渡方式,并且有一个很好的列表,列出了您可以执行的所有操作。然后完成 block 让您指定完成后要做什么。在这种情况下,它将切换到选项卡 1,因此它是新的主 Controller

关于iphone - 在 TabBarController 中的选项卡之间切换/导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6348518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com