gpt4 book ai didi

选中后iOS刷新标签栏项目

转载 作者:行者123 更新时间:2023-12-01 19:11:30 24 4
gpt4 key购买 nike

我有一个可以浏览到子屏幕的标签栏。

选择选项卡项目时,重新启动选项卡栏项目(第一个屏幕)。

Tab bar picture
所以基本上当你选择第一个标签栏(见上图)并从 tableview 中选择一些东西时,你被定向到集合 View (黑屏)。当您选择第二个标签栏项目并返回到标签栏中的第一个项目时,它会从上次停止的地方继续(黑屏)。

我如何让它重新开始?

我试过用这个,

- (void) viewDidLoad{
[self.tabBarController addObserver:self forKeyPath:@"selectedViewController" options:NSKeyValueObservingOptionNew context:@"changedTabbarIndex"]; }


- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void
*)context{
[self viewDidAppear:YES]; }

但这只会在第二次点击时重新加载屏幕。

最佳答案

从我在你的图片中看到的,你有 UINavigationController作为每个标签栏项目的根 View Controller ,所以你可以做的是在你的 UITabBarController 中实现以下方法:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController  {
if (tabBarController.selectedIndex == YOUR_TAB_INDEX) {
//YOUR_TAB_INDEX is the index of the tab bar item for which you want to show the rootView controller
UINavigationController *navController = (UINavigationController*)viewController;
[navController popToRootViewControllerAnimated:YES]
}

}

这将删除所有添加到 UINavigationController 的 View Controller 。这是标签栏项目的根 View Controller

关于选中后iOS刷新标签栏项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16298376/

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