我需要一些想法或指出以下问题:
我有一个以TabBarView开头的应用程序 - 在某些标签中有不同的View / ViewControllers,它们通过seques连接。 如果更改了活动Tab,我希望(现在)打开Tab加载此Tab的“Start”-View / ViewController,而不是此Tab上最后一个活动的View / ViewController。 我怎么能这样做?
答案 0 :(得分:1)
我建议您使用UITabBarDelegate
方法:tabBarController:didSelectViewController:
结合UINavigationController
方法:popToRootViewControllerAnimated:
因此,当用户选择选项卡时,您可以确保导航从根控制器开始。
编辑回应评论:
这不是一个理想的情况,但您可以在app委托中引用UITabBarController。 E.g:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Get reference to Tab Bar Controller as the root view
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
// Set Delegate
tabBarController.delegate = self;
return YES;
}
然后,您可以实现类似于:
的UITabBarDelegate方法-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
// Pop to root if the selected controller is a navigation controller.
if ([viewController isKindOfClass:[UINavigationController class]]) {
[((UINavigationController *)viewController) popToRootViewControllerAnimated:NO];
}
}
我还没有测试过这个!