[英]How do I make the transition between view controllers and return from each to the main view con.?
I have a MainViewController with a table view.我有一个带有表格视图的 MainViewController。 When I click on a cell, the ChartViewController opens.
当我单击一个单元格时,ChartViewController 将打开。 It has a Back button to return to the MainViewController and a button to go to the SummaryViewController.
它有一个返回到 MainViewController 的返回按钮和一个返回到 SummaryViewController 的 go 的按钮。 The SummaryViewController button has a button to go to the ChartViewController and a Back button, but it also goes back to the ChartViewController.
SummaryViewController 按钮有一个到 go 到 ChartViewController 的按钮和一个返回按钮,但它也返回到 ChartViewController。 How do I return to the MainViewController using the Back button?
如何使用 Back 按钮返回 MainViewController?
Transition code from Chart View Controller to SummaryViewController:从图表视图 Controller 到 SummaryViewController 的转换代码:
@IBAction func onSummaryButtonTapped(_ sender: Any) {
let storyboard = UIStoryboard(name: "Main", bundle: .main)
if let viewController = storyboard.instantiateViewController(withIdentifier: "StockSummaryViewController") as? StockSummaryViewController {
navigationController?.pushViewController(viewController, animated: false)
}
}
add in ChartViewController when you create SummaryViewController在创建 SummaryViewController 时添加 ChartViewController
... summaryViewController.delegate = self ... summaryViewController.delegate = self
in SummaryViewController add a variable在 SummaryViewController 添加一个变量
weak var delegate: SummaryViewControllerDelegate?
and when user click "backButton" in SummaryViewController add当用户在 SummaryViewController 中单击“backButton”时添加
{
...
delegate?.backClick()
}
in ChartViewController add在 ChartViewController 添加
extension ChartViewController: SummaryViewControllerDelegate {
func backClick() {
self.dismiss(animation: true, completion: nil)
//or
//self.popViewController(animation: true)
}
}
and finally define anywhere最后在任何地方定义
protocol SummaryViewControllerDelegate: class {\
func backClick()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.