segue到嵌套表视图控制器后缺少选项卡栏

时间:2018-06-16 12:46:08

标签: ios swift

enter image description here

我的目标是在点击TABLE2

按钮后显示VC1的指定行

执行从VC1TABLE1然后再到TABLE2的segue后,我的标签栏丢失了。我在故事板上有问题,或者我必须在做segue之后手动添加这个标签栏?我正在做segue到导航控制器,然后我将performSegue从TABLE1调用到TABLE2

在segue之后

TABLE2看起来像:

enter image description here

但看起来应该是这样的:

enter image description here

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"
    }
}

2 个答案:

答案 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)

检查故事板中的 TABLE2 viewController。 请务必取消选中“在推送时隐藏底栏”。

或尝试强制显示标签栏。

Item Exporters

enter image description here