简体   繁体   English

显示具有选定TableView项和选项卡栏控制器的View Controller

[英]Show View Controller with Selected TableView Item and Tab Bar Controller

I'm trying to present a SharkProfileTableViewController from my Main.storyboard file with a TabBarViewController from a button action in a modal view in Upload.storyboard that has no tab bar. 我想提出一个SharkProfileTableViewController从我Main.storyboard文件与TabBarViewController从一个模态视图按钮动作Upload.storyboard一个没有标签栏。

The ViewController I'm trying to present is a selected item from a SharksTableViewController tableview based on the data from the modal view. 我要呈现的ViewController是基于模态视图中数据的SharksTableViewController tableview中的选定项。

How do I show the SharkProfileViewController along with the TabBarViewController ? 如何显示SharkProfileViewControllerTabBarViewController

@IBAction func viewProfileButtonPressed(_ sender: UIButton) {
    let stb = UIStoryboard(name: "Main", bundle: nil)
    let tabBar = stb.instantiateViewController(withIdentifier: "tabBar") as! TabBarViewController
    let sharkTabBar = stb.instantiateViewController(withIdentifier: "sharkTableView") as! SharksTableViewController
    let sharkProfile = stb.instantiateViewController(withIdentifier: "sharkProfile") as! SharkProfileTableViewController

    sharkProfile.selectedShark = shark as JSONObject

    tabBar.selectedIndex = 3

    self.present(tabBar, animated: true) {

    }

}

TabBarController - the 'Shark' tab is the tab that should show TabBarController-“鲨鱼”标签是应显示的标签 TabBarController

SharksTableViewController - when selecting an item in this tableview it presents the ... SharksTableViewController-在此tableview中选择一个项目时,会显示... SharksTableViewController

SharkProfileTableViewController - this is the view I'm trying to present (with the tab bar showing) SharkProfileTableViewController-这是我要呈现的视图(显示标签栏) SharkProfileTableViewController

If you want to pass any data to SharkProfileTableViewController that you have added in UITabbarController then you can access it using the viewControllers property of UITabbarController . 如果你想传递任何数据SharkProfileTableViewController您在已添加UITabbarController ,那么你可以通过访问它viewControllers财产UITabbarController viewControllers property will return array of UIViewController so you need to access it using subscript with your controller index in Tabbar. viewControllers属性将返回UIViewController数组,因此您需要使用下标以及Tabbar中的控制器索引来访问它。

@IBAction func viewProfileButtonPressed(_ sender: UIButton) {
    let stb = UIStoryboard(name: "Main", bundle: nil)
    let tabBar = stb.instantiateViewController(withIdentifier: "tabBar") as! TabBarViewController
    //If SharkProfileTableViewController at 4 position in tabbar then access it from array like this
    let nav = tabBar.viewcontrollers?[3] as! UINavigationController 
    let sharkProfile = stb.instantiateViewController(withIdentifier: "sharkProfile") as! SharkProfileTableViewController
    sharkProfile.selectedShark = shark as JSONObject        
    tabBar.selectedIndex = 3        
    self.present(tabBar, animated: true) {
        nav.pushViewController(sharkProfile, animated: false)
    }
}

Now you need to simply change index in viewcontrollers?[3] to access other controller from array. 现在,您只需要简单地更改viewcontrollers?[3]索引viewcontrollers?[3]即可从数组访问其他控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当选择选项卡栏项目视图控制器时调用viewWillDisappear - viewWillDisappear called when tab bar item selected view controller set 如何在1项标签栏控制器中制作顶部标签栏以在swift中显示多个视图控制器? - How to make top tab bar inside 1 item tab bar controller to show multiple view controller in swift? iOS如何选择没有标签栏项目的标签栏视图控制器? - iOS How to implement Tab Bar View Controller with no tab bar item selected? Swift 2从视图控制器返回到选项卡栏控制器中的选定选项卡 - Swift 2 Return to a selected tab in tab bar controller from view controller 在选项卡栏控制器中选择时以模态显示视图控制器 - Present a View Controller modally when selected in Tab Bar Controller iOS标签栏控制器:未选择标签项的首页消息 - iOS Tab Bar Controller : home message without tab item selected 标签栏控制器更改指向现有项目的新视图控制器 - Tab bar controller change pointing to new view controller for existing item TableView Controller +导航控制器+标签栏 - TableView Controller + Navigation Controller + Tab bar 数据将tableview单元格传递到Swift中的标签栏视图控制器 - Data pass tableview cell to tab bar view controller in Swift 在Swift中的选项卡栏中将数据从TableView传递到View Controller - Pass data from tableview to view controller in tab bar in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM