It's getting complicated when I think about it, but I vaguely grasp the flow.
** side that asks ** to use the method ".
NextViewController.swift
// 1.Set rules
protocol CatchProtocol {
func catchData(count:Int)
}
class NextViewController: UIViewController {
var count:Int = 0
// 2.Make 1 a variable named deledele
var deledele:CatchProtocol?
@IBAction func push(_ sender: Any) {
// 3.Activate. Pass arguments if needed
deledele?.catchData(count:count)
}
The ** side who is asked ** to use the method.
ViewController.swift
// 1.declare
class ViewController: UIViewController, CatchProtocol {
@IBOutlet weak var label: UILabel!
var count:Int = 0
override func viewDidLoad() {
super.viewDidLoad()
}
// 2.Delegate method. Created by pressing fix with an error when declaring
func catchData(count: Int) {
label.text = String(count)
}
@IBAction func next(_ sender: Any) {
performSegue(withIdentifier: "next", sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let nextVC = segue.destination as! NextViewController
//The description "I was entrusted with the deledele of NextViewController"
nextVC.deledele = self
}
}
ββIt's really easier to understand when other people such as team members see it if you use delegate
instead of deledele
.
ββI understand the flow somehow, but the last self
is vague
Recommended Posts