gpt4 book ai didi

当将数据传回主视图时,Swift NavigationBar 被隐藏

转载 作者:行者123 更新时间:2023-11-30 12:52:37 25 4
gpt4 key购买 nike

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

This is Main View

enter image description here

and when I Select "TestToNextPage"(tableViewCell) will push to SecondView like this photo

enter image description here

and when I select VC2 "Test2" button will pass data back to MainView but the NavigationBar will dissmiss

enter image description here

I also try this code in MainView and SecondView but is didn't work

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

MainView code for tableViewCell

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 code

 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)!
}
}

我的 Storyboard enter image description here

有人有任何想法或有其他最好的方法吗?感谢伙伴的帮助

最佳答案

尝试在 Storyboard 中的第二个 View Controller 上嵌入导航 Controller ,然后将 View Controller 连接到刚刚添加的导航 Controller 。

关于当将数据传回主视图时,Swift NavigationBar 被隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40777405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com