Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.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
Ios 如何以编程方式更改所选选项卡?_Ios_Iphone - Fatal编程技术网

Ios 如何以编程方式更改所选选项卡?

Ios 如何以编程方式更改所选选项卡?,ios,iphone,Ios,Iphone,我想在刷卡时以编程方式更改选项卡。它已成功实现,但我想更改选项卡选择。我使用了以下代码: UINavigationController *navController = [[appDelegate.tabBarController viewControllers] objectAtIndex:1]; [appDelegate.tabBarController.delegate tabBarController:appDelegate.tabBarController shouldSelectVi

我想在刷卡时以编程方式更改选项卡。它已成功实现,但我想更改选项卡选择。我使用了以下代码:

UINavigationController *navController = [[appDelegate.tabBarController viewControllers] objectAtIndex:1];
[appDelegate.tabBarController.delegate tabBarController:appDelegate.tabBarController shouldSelectViewController:[[navController viewControllers] objectAtIndex:0]];

[appDelegate.tabBarController.tabBar setSelectedItem:[[appDelegate.tabBarController.tabBar items] objectAtIndex:1]];
但这是一个例外:

***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因是:“不允许直接修改由选项卡栏控制器管理的选项卡栏。”


尝试:
[self-setSelectedIndex:index]

作为自我
UITabBarController
index
作为视图控制器的索引(从
viewControllers
array),您希望被选中

请参阅文档

试试这个

如果要选择索引1处的制表符

[appDelegate.tabBarController setSelectedIndex:1];

请勿修改由选项卡栏控制器(UITabBarController类的实例)管理的选项卡栏。如果这样做,系统将引发异常。仅通过选项卡栏控制器API修改托管选项卡栏或其项。 如果选项卡栏不由选项卡栏控制器管理,则可以使用此类的方法直接修改选项卡栏

被引用


谢谢你的答复。。但这对我不起作用。@PanktiPatel您是否实现了
shouldSelectViewController:
UITabbarController
@PanktiPatel能否显示
shouldSelectViewController:
方法实现?-(BOOL)tabBarController:(UITabbarController*)tabBarController shouldSelectViewController:(UIViewController*)viewController NS_可用_IOS(3_0){[appDelegate.tabBarController setSelectedIndex:appDelegate.tabSelectedIndex];返回YES;}@PanktiPatel为什么“[appDelegate.tabBarController setSelectedIndex:appDelegate.tabSelectedIndex];”?这是我实现的,但会导致崩溃。
[yourTabBar setSelectedItem:[yourTabBar.items objectAtIndex:0]];
[yourTabBar setSelectedIndex:0];