IOS開発日記(4)-ページジャンプの問題

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
}

2ページ目のメインコード:

//返回到第一个页面
self.navigationController?.popViewController(animated: true)

参照:

https://www.cnblogs.com/bhlsheji/p/5168710.html

 

2.ページの逆方向の値の転送(順方向の値の転送は非常に簡単です。別のページのパラメーターに値を割り当てるだけです。ここでは詳しく説明しません)

逆パス値:最初のページが2番目のページにジャンプし、次に2番目のページがいくつかの操作を実行してから最初のページに戻り、値を最初のページに渡します

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

 

おすすめ

転載: blog.csdn.net/hzkcsdnmm/article/details/106022938