我的目标是在点击TABLE2
VC1
的指定行
执行从VC1
到TABLE1
然后再到TABLE2
的segue后,我的标签栏丢失了。我在故事板上有问题,或者我必须在做segue之后手动添加这个标签栏?我正在做segue到导航控制器,然后我将performSegue从TABLE1
调用到TABLE2
TABLE2
看起来像:
但看起来应该是这样的:
VC1
的代码:
class FirstViewController: UIViewController {
@IBAction func performSegueTapped(_ sender: UIButton) {
self.performSegue(withIdentifier: "segueFromMainWindow", sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segueFromMainWindow" {
let destinationNavigationController = segue.destination as! UINavigationController
let targetController = destinationNavigationController.topViewController as? FirstTableViewController
targetController?.performSegue(withIdentifier: "testSegue", sender: nil)
}
}
}
TABLE1
的代码:
class FirstTableViewController: UITableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "testSegue", sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destCtrl = segue.destination as! SecondTableViewController
destCtrl.testLabelText = "hello"
}
}
答案 0 :(得分:1)
在Main.storyboard中为SecondTableViewController设置自定义标识符,然后将IBAction分配给按钮,如下所示:
@IBAction func performSegueButtonTouched(_ sender: UIButton) {
let tabBarViewControllers = tabBarController?.viewControllers
let tableNavigationController = tabBarViewControllers?[1] as! UINavigationController
let firstTableViewController = tableNavigationController.topViewController as! FirstTableViewController
let mainStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
let secondTableViewController = mainStoryboard.instantiateViewController(withIdentifier: "SecondTableViewController") as! SecondTableViewController
secondTableViewController.testLabelText = "Something"
tabBarController?.selectedIndex = 1
tableNavigationController.setViewControllers([firstTableViewController, secondTableViewController], animated: true)
}
答案 1 :(得分:0)