1.从一个UITabBarViewController跳转到一个ViewController:
第一个页面主要代码:
//添加手势
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)
}
返回原页面再显示TabBar:
override func viewWillAppear(_ animated: Bool) {
self.tabBarController?.tabBar.isHidden=false
}
第二个页面主要代码:
//返回到第一个页面
self.navigationController?.popViewController(animated: true)
参考:
https://www.cnblogs.com/bhlsheji/p/5168710.html
2.页面反向传值(正向传值很简单只需要给另一个页面的参数赋值就可以啦,这里不做详细介绍了)
反向传值:第一个页面跳转到第二个页面,然后第二个页面进行一些操作后返回第一个页面并传值给第一个页面
先说第二个页面主要代码:
//指定一个协议的变量
var delegate:AirportListViewControllerDelegate?
//声明一个协议
protocol SecondViewControllerDelegate:class{
func sendData(data:String)
}
//在按钮的点击函数中调用协议方法并返回第一个页面
delegate?.sendData(data: “test”)
self.navigationController?.popViewController(animated: true)
第一个页面主要代码
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
}
}