我想通過刷卡以編程方式更改選項卡。它的實現成功,但我想改變選項卡的選擇。我用下面的代碼:如何以編程方式更改選定的選項卡?
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]];
但是這給例外:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
感謝您的答覆..引用,但這並不爲我工作。 –
@PanktiPatel是否實現了'shouldSelectViewController:''UITabbarController'的代理方法 – Akhilrajtr
是的,我做到了。 –