ios - 模态视图在关闭时更改我的选项卡

标签 ios modal-dialog tabbar

我有一个带有 2 个选项卡的 TabBarViewController:tab(A) 和 tab(B)。这两个选项卡内部都有 UITableView,当我单击一个单元格时,会出现一个模态视图。如果我单击作为默认选项卡的选项卡 (A),一切正常,但问题是当我转到选项卡 (B) 并在打开模态视图后,当我关闭模态视图时,选项卡栏会自动返回到默认选项卡是选项卡(A)。 我试过了:

[self dismissViewControllerAnimated:YES completion:nil];

还有:

[self.presentingViewController dismissViewControllerAnimated:YES
                                                      completion:nil];

返回。但我有相同的结果。

最佳答案

您可以这样保存在标签栏中选择的最后一个 View Controller :

    -(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    {
         _previousViewControllerIndex = // get index of your tab here
    }

关闭模型 View 后,将在您的 UITabBarController 上调用 viewDidAppear,您可以通过编程方式选择之前选择的 Controller :

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
  [self.tabBarController setSelectedIndex:_previousViewControllerIndex];
}

关于ios - 模态视图在关闭时更改我的选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29548190/

相关文章:

ios - 升级到 xcode 7 后无法在设备上运行应用程序

objective-c - 在NSArray中增加NSNumber

html - 模式背景元素的正确 HTML 角色和其他相关属性 (TypeScript React)

安卓运行时异常 :requestFeature() must be called before adding content in DialogFragment

iphone - 有没有办法阻止选项卡栏项目的配置?

ios - 在 Swift 中删除 TabBar 项目

ios - 为什么 [UIScreen mainScreen].bounds] 没有返回全屏大小?

ios - 我们可以在 iPad 的单个 View 中有两个导航流吗?

javascript - 任何人都可以建议在模式打开时在 Firefox 中使用箭头键滚动页面的解决方案吗?

android - 相对布局 : align view to child of sibling viewgroup