IOS开发日记(四)—— 页面跳转问题

3 篇文章 0 订阅

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值