I am working on a Magic the Gathering Counter app. For my app, I want to click twentyLife()
, thirtyLife()
, or fourtyLife()
to change the value of a variable in another view controller (i.e. FifthViewController.)
Second view controller code:
import UIKit
class SecondViewController: UIViewController {
var vcFive = FifthViewController()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func twentyLife() {
vcFive.lifePoints.text = String(20)
}
@IBAction func thirtyLife() {
vcFive.lifePoints.text = String(20)
}
@IBAction func fortyLife() {
vcFive.lifePoints.text = String(20)
}
I try and call out the fifthViewController as a variable to change my life points text but it does not work.
Here is my code for the fifthViewController:
import UIKit
class FifthViewController: UIViewController {
@IBOutlet weak var lifePoints: UILabel!
var counter = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func lifeUp() {
counter += 1
lifePoints.text = String(counter)
}
@IBAction func lifeDown() {
counter -= 1
lifePoints.text = String(counter)
}
Any help would be appreciated. This is my first app I have been trying to work on from scratch