Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在选项卡栏的特定选项卡中打开应用程序_Objective C_Ios_Tabbar - Fatal编程技术网

Objective c 在选项卡栏的特定选项卡中打开应用程序

Objective c 在选项卡栏的特定选项卡中打开应用程序,objective-c,ios,tabbar,Objective C,Ios,Tabbar,我有一个带有5个标签的标签栏的应用程序(没有自定义类的常规标签栏)。当我启动应用程序时,左侧选项卡打开。我想先打开中间的那个。我试过把 [self.tabBarController setSelectedIndex:3]; 在ViewDidLoad中,首先打开但选项卡未切换的ViewController。 我可以看到它高亮显示但未选中。如果我将上面的代码放在视图下,它将在第一次运行时被选中,但当我不时选择左侧选项卡时,它将跳转到中间的选项卡 我也尝试过,但没有成功: DetailsViewCo

我有一个带有5个标签的标签栏的应用程序(没有自定义类的常规标签栏)。当我启动应用程序时,左侧选项卡打开。我想先打开中间的那个。我试过把

[self.tabBarController setSelectedIndex:3];
在ViewDidLoad中,首先打开但选项卡未切换的ViewController。 我可以看到它高亮显示但未选中。如果我将上面的代码放在
视图下,它将在第一次运行时被选中,但当我不时选择左侧选项卡时,它将跳转到中间的选项卡

我也尝试过,但没有成功:

DetailsViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailsViewController"];
[self.navigationController pushViewController:vc animated:true];    

我做错了什么?

需要打电话

tabBarController.selectedIndex = desiredIndex;

在应用程序IDLaunch内部。

尝试在应用程序:didFinishLaunchingWithOptions:中设置它,如果您的选项卡栏控制器与rootViewController类似

`[self.window.rootViewController.tabBarController setSelectedIndex:3];`

在序列图像板中,将自定义类设置为tabbarController,并在该自定义类中设置

-(void) viewDidLoad
{
    [self.tabBarController setSelectedIndex:3];
}

我过去做过一些粗俗的事。我发现,为了使每个选项卡都处于活动状态,在我的ApplicationIDFinishLaunching中,我需要循环所有视图控制器,然后访问“视图”属性:

for(viewController in arrayOfViewController)
{
    // will load the view controller into memory
    [viewController view];
}

不知道你是否能利用它。

这是唯一对我有效的解决方案。在appdelegate中:

UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController; 
[tabBar setSelectedIndex:2];

选项卡栏是从Interface builder添加的还是使用code?界面添加的。如果我理解正确,将触发的segaues拖到viewcontrollers可能会对您有所帮助。请尝试在application:didfishlaunchingwithoptions:like[self.window.rootViewController.tabBarController setSelectedIndex:3]中进行设置;这是唯一对我有效的解决方案。写在这里,这样我将在2天内更新问题。在appdelegate中:
UITabBarController*选项卡=(UITabBarController*)self.window.rootViewController;[tabBar setSelectedIndex:2]