1. Jump from a UITabBarViewController to a ViewController:
The main code of the first page:
//添加手势
myLabel.isUserInteractionEnabled=true
let myTapGes=UITapGestureRecognizer(target: self, action: #selector(self.labelClick(tapGes:)))
myLabel.addGestureRecognizer(myTapGes)
@objc private func labelClick(tapGes:UITapGestureRecognizer){
self.tabBarController?.tabBar.isHidden=true
self.navigationController?.pushViewController(MyViewController(), animated: true)
}
Return to the original page and display the TabBar:
override func viewWillAppear(_ animated: Bool) {
self.tabBarController?.tabBar.isHidden=false
}
The main code of the second page:
//返回到第一个页面
self.navigationController?.popViewController(animated: true)
reference:
https://www.cnblogs.com/bhlsheji/p/5168710.html
2. Page reverse transfer value (forward value transfer is very simple, just assign values to the parameters of another page, and I won’t go into details here)
Reverse pass value: the first page jumps to the second page, and then the second page performs some operations and then returns to the first page and passes the value to the first page
Let me talk about the main code of the second page:
//指定一个协议的变量
var delegate:AirportListViewControllerDelegate?
//声明一个协议
protocol SecondViewControllerDelegate:class{
func sendData(data:String)
}
//在按钮的点击函数中调用协议方法并返回第一个页面
delegate?.sendData(data: “test”)
self.navigationController?.popViewController(animated: true)
Main code of the first page
if let vc=airportListBoard.instantiateViewController(withIdentifier: "SecondID") as? SecondViewController{
vc.delegate=self //关键是这个地方要指定一下SecondViewController的delegate
self.tabBarController?.tabBar.isHidden=true
self.navigationController?.pushViewController(vc, animated: true)
}
extension FirstViewController:SecondViewControllerDelegate{
func sendData(data: String) {
label.text=data
}
}