[英]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
? 如何显示SharkProfileViewController
和TabBarViewController
?
@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-“鲨鱼”标签是应显示的标签
SharksTableViewController - when selecting an item in this tableview it presents the ... SharksTableViewController-在此tableview中选择一个项目时,会显示...
SharkProfileTableViewController - this is the view I'm trying to present (with the tab bar showing) 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.