gpt4 book ai didi

ios - 标签栏 Controller 需要点击 2 次返回主视图

转载 作者:行者123 更新时间:2023-12-01 16:02:28 24 4
gpt4 key购买 nike

我已经设置了一个标签栏 View Controller 并与导航 Controller 链接,
引用这张图片。 enter image description here我面临的问题是这张图片是“更多”标签栏页面enter image description here当我单击十字按钮时,它会将主视图 Controller 推送到另一个 View 。但是当我点击另一个选项卡并返回更多选项卡时, View Controller 仍然停留在主视图 Controller 而不是更多选项卡源 Controller 。我需要点击更多选项卡 2 次,然后它才会返回到更多选项卡 View Controller 。下面的代码是我选择项目时的标签栏 Controller 。

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSLog(@"didSelectItem: %ld", (long)item.tag);

if (item.tag == 0) {
//try to dismiss home view controller in this way, but it won't work
[self.navigationController popToRootViewControllerAnimated:YES];

NSString *str = @"TAB 1";
NSLog(@"%@", str);
}
}

最佳答案

更新了 Swift 4.1 iOS 11.2 的答案

class TabBarMenuView: UITabBarController {

override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
if (self.selectedViewController?.isKind(of: UINavigationController.self))!
{
let nav = self.selectedViewController as! UINavigationController
nav.popToRootViewController(animated: false)
}
}
}

关于ios - 标签栏 Controller 需要点击 2 次返回主视图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44692021/

24 4 0