[英]ViewController still stays after unwind segue
因此,我有多个控制器,我们称它们为A,B和C。
当我转到A并在表视图中选择一个项目时,我被传送到B,可以在其中编辑项目并保存。 现在,当我按保存时,我有一个轻松的选择,可将我带到主页C。
但是,当我再次进入A时,视图仍然停留在B上,我必须再次按一下曾经回到A的tabBarItem,然后回到A。为什么会这样,我只想让A出现再按一次,B消失。
我已经尝试过以下代码:
self.presentingViewController?.dismiss(animated: false, completion:nil)
self.dismiss(animated: false, completion: nil)
在segue和保存按钮代码中,但似乎什么也没有发生。
好的,这是根据要求提供的更多上下文:
这是ViewController A:
这是viewController B:
所以当我按保存时,它会将我传送到viewcontroller C:这就是viewcontrollerC:
然后,使用选项卡栏,当我回到viewcontroller a时,我对此表示欢迎:
如您所见,选项卡在第三个选项上,但是我对Viewcontroller B表示欢迎,然后,我必须再次单击第三个选项(一个标题为collection)以返回到viewcontrollerA。
希望事情变得更清楚,请告诉我是否需要任何代码。
如果这是您需要的,请尝试以下操作:
class CViewController : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "C"
view.backgroundColor = .yellow
let button = UIButton(type: .system)
button.setTitle("Go to A", for: .normal)
button.addTarget(self, action: #selector(goToA), for: .touchUpInside)
button.frame = CGRect(x: 100, y: 200, width: 100, height: 40)
view.addSubview(button)
}
@objc func goToA() {
let AVC = AViewController()
self.navigationController?.pushViewController(AVC, animated: true)
}
}
class AViewController : UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "A"
view.backgroundColor = .green
tableView.delegate = self
tableView.dataSource = self
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = "Cell \(indexPath.row)"
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let BVC = BViewController()
self.navigationController?.pushViewController(BVC, animated: true)
}
}
class BViewController : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "B"
view.backgroundColor = .cyan
let button = UIButton(type: .system)
button.setTitle("save", for: .normal)
button.addTarget(self, action: #selector(save), for: .touchUpInside)
button.frame = CGRect(x: 100, y: 200, width: 100, height: 40)
view.addSubview(button)
}
@objc func save() {
self.navigationController?.popToRootViewController(animated: true)
}
}
如果您有任何疑问,请随时。 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.