gpt4 book ai didi

ios - 在使用 Storyboard 和 segue 时打开它之前选择 tabbarcontroller 的默认选项卡

转载 作者:行者123 更新时间:2023-12-01 18:14:32 25 4
gpt4 key购买 nike

在我的 iOS 应用程序中,我有 tabbarviewcontroller它不是应用程序的第一个 View Controller 。

实际上它是第二个 View Controller 。第一个 View Controller 是仪表板,然后通过按下其中一个按钮应用程序按下 tabbarcontroller到导航栏并显示tabbarcontroller (我都是用 Storyboard做的)

根据某些情况,tabbarviewcontroller 应该显示的默认选项卡是差异。例如,有时我应该打开 tabbarcontroller 以便显示第二个选项卡。有时我应该打开它以便显示第一个选项卡。有人知道我们该怎么做吗?我在网上搜索,但没有找到任何好的答案。

最佳答案

我相信你可以设置 Controller 的 selectedIndex 。试试 [myTabBarController setSelectedIndex:myInt];
如果您使用的是 segue,则应在 prepare for segue 方法中进行设置。这是一个例子。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"myIdentifier"]){
[((UITabBarController*)segue.destinationViewController) setSelectedIndex:myInt];
}
}

关于ios - 在使用 Storyboard 和 segue 时打开它之前选择 tabbarcontroller 的默认选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23662489/

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