Swift 按“将数据快速传输到第一个视图”;“后退”;按钮

Swift 按“将数据快速传输到第一个视图”;“后退”;按钮,swift,uinavigationcontroller,Swift,Uinavigationcontroller,朋友们好。导航控制到第二个屏幕。我得走了 到第二个屏幕上有按钮(SonuclarıListele)的一个屏幕,我必须 将第一个屏幕上的数字设置为“2” 第一视图 class KonularViewController: UIViewController { var number : Int? @IBAction func barButtonKonuEkle(_ sender: Any) { let childViewController = storybo

朋友们好。导航控制到第二个屏幕。我得走了 到第二个屏幕上有按钮(SonuclarıListele)的一个屏幕,我必须 将第一个屏幕上的数字设置为“2”

第一视图

class KonularViewController: UIViewController {

    var number : Int?

    @IBAction func barButtonKonuEkle(_ sender: Any) {
        let childViewController = storyboard?.instantiateViewController(withIdentifier: "KonuEkleViewController") as! KonuEkleViewController
        navigationController?.pushViewController(childViewController, animated: true)
    }
}
第二视图

class AramaViewController: UIViewController {
    @IBOutlet weak var btn1: UIButton!
    @IBOutlet weak var btn2: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        btn1.isSelected = true
    }

    @IBAction func btnListele(_ sender: Any) {
      //First View "Number" variable on the first screen will be 2
    }

    @IBAction func btn_box(sender: UIButton) {

        if sender.titleLabel?.text == "En Yeniler"
        {
        btn1.isSelected = true
        btn2.isSelected = false
        }
        else
        {
        btn2.isSelected = true
        btn1.isSelected = false
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

一个策略是拥有一个第三级的模型,它可以保持状态

class Model {
   static let shared = Model()
   var count: Int = 1
}

class AramaViewController: UIViewController {
    @IBAction fund btnListele(_ sender: Any) {
      Model.shared.count += 1
      //First View "Number" variable on the first screen will be 2
}

class KonularViewController: UIViewController {
    override func viewWillAppear(animated:Bool) {
        super.viewWillAppear(animated: animated)
        numberView.text = "\(Model.shared.count)"  //display your number here
    }
}
另一种选择 在导航控制器视图控制器阵列中返回到上一个视图并设置属性。这有点脆弱

class KonularViewController: UIViewController {
    var count: Int = 1
    override func viewWillAppear(animated:Bool) {
        super.viewWillAppear(animated: animated)
        numberView.text = "\(count)"  //display your number here
    }
}

class AramaViewController: UIViewController {
    @IBAction fund btnListele(_ sender: Any) {
      let numberOfViews = navigationController.viewControllers.count
      if count > 1, let previousViewController = self.navigationController.viewControllers[numberOfViews-2] as? KonularViewController 
      previousViewController.count += 1
      //First View "Number" variable on the first screen will be 2
}

假设KonularViewController标识符为“KonularViewController”。 在AramaViewController中:

@IBAction func btnListele(_ sender: Any) {
      //First View "Number" variable on the first screen will be 2
      let konularViewController = storyboard?.instantiateViewController(withIdentifier: "KonularViewController") as! KonularViewController
      konularViewController.number = 2
      navigationController?.pushViewController(childViewController, animated: true)
}

我看不出你的观点中有什么数字,你想要实现什么有点困惑。如果要在推送UIViewController之前增加数字,只需在推送之前增加数字即可。在调用
AramaViewController
btnListele
时,是否要将
FirstViewController的
number
设置为2?