大家好,我是新手,我在网上搜寻了很长时间。但是没用。请帮助或尝试给出一些想法来实现这一目标。


  这是主视图


swift - 将数据传递回主 View 时,Swift导航栏被隐藏-LMLPHP


  当我选择“ TestToNextPage”(tableViewCell)将推
  SecondView赞这张照片


swift - 将数据传递回主 View 时,Swift导航栏被隐藏-LMLPHP


  当我选择VC2时,“ Test2”按钮会将数据传递回MainView
  但NavigationBar将关闭


swift - 将数据传递回主 View 时,Swift导航栏被隐藏-LMLPHP


  我也在MainView和SecondView中尝试了此代码,但没有用


override func viewWillLayoutSubviews() {
        self.navigationController?.navigationBar.isHidden = false
    }



  tableViewCell的MainView代码


private func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath)-> UITableViewCell {
let cellIdentifer = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifer, for: indexPath as IndexPath)
    cell.textLabel?.text = "TestToNextPage"
    cell.accessoryType = .disclosureIndicator
    return cell
   }
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
 {
     let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
     let SecondViewController = mainStoryboard.instantiateViewController(withIdentifier: "SecondViewController")
        self.navigationController?.pushViewController(SecondViewController, animated: true)



  SecondView Btn代码


 var MainVC: ViewController
 @IBAction func TestBtn(_ sender: UIButton){
        MainVC?.MainArray = TestArray      //pass TestArray to MainArray
        MainVC?.delegate = self
        self.performSegue(withIdentifier: "SecondSegue", sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "SecondSegue" {
            MainVC = segue.destination as? ViewController
            MainVC?.MainArray = self.TestArray
    }
    func dismissMainViewController(Controller:UIViewController){
        if MainVC == Controller as? ViewController{
            self.TestArray = (MainVC?.MainArray)!
        }
    }


我的故事板
swift - 将数据传递回主 View 时,Swift导航栏被隐藏-LMLPHP

是否有人有任何想法或有另一种最佳方法?
谢谢你的帮助

最佳答案

尝试将导航控制器嵌入到情节提要中的第二个View Controller上,然后建立从View Controller到刚添加的Navigation Controller的连接。

关于swift - 将数据传递回主 View 时,Swift导航栏被隐藏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40777405/

10-14 19:55
查看更多