ios - 如何从 subview Controller 中找到选项卡栏方案中选定的选项卡

标签 ios swift uitabbarcontroller

我使用选项卡栏通过单个 TableView Controller 显示相同数据的三个过滤 View 。为了确定适当的过滤器,我需要找出从 subview Controller 中选择了哪个选项卡。我使用 Storyboard来创建此结构,因此我没有选项卡栏 View Controller 。

最佳答案

两种可能的方式:

  1. 在你的 subview Controller 中

    UITabBarController *tvc = (UITabBarController *)self.parentViewController;

    NSInteger 索引 = tvc.selectedIndex;

  2. 使用单例来保存 selectedIndex

关于ios - 如何从 subview Controller 中找到选项卡栏方案中选定的选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31040889/

相关文章:

ios - 使用 DragGesture 调整 SwiftUI View 的框架会在所有维度上调整其大小

iOS:如何很好地放大图像?

swift - bool 表达式 : What's the inverse of a 'let myString = aPossibleString' ?

ios - 如何识别 UITabBarController 跟随哪个 "relationship"?

ios - 无法将 UIBarButtonItem 添加到 UITabBarController 内的 navigationController

ios - UITextView 接收文本形式的听写,但文本在 textView.text 属性中为 nil

iphone - 使用 Google Maps for iOS 检索多个标记的位置、标题和片段

iOS, swift : animation controlled by gesture

ios - Cocoapods : Issue with pod which contains resource folder Assets. xcassets

ios - 仅对 AVCaptureVideoPreviewLayer 禁用旋转