G
G
grambumbez2020-11-15 00:23:56
iOS
grambumbez, 2020-11-15 00:23:56

How to pass the state of a button (checkBox) through UserDefaults to another controller?

Greetings!
please help, there is a PageVC with VC1, VC2, VC3 scrolling and on the last VC3 there is a checkBox (tick).
I want that when the user clicked on the checkBox (checked) the next time he would not be shown PageVC with a VC scroll, but another VC would immediately open.

save the state of the checkBox through UserDefaults and then apply it within one VC turns out, but passing this state to the first screen of the VC1 scroll and checking whether the button was pressed does not work ((((

This is VC3 from which you need to transfer the state of
@IBAction func checkBoxButton (_ sender : Any) {
self.checkBox.isSelected = !self.checkBox.isSelected
delegate?.back(tester: UserDefaults.standard.set(self.checkBox.isSelected, forKey: "stopWelcomePage") as! Bool)
}
and this is VC1 where to pass and check this state

import UIKit

protocol CountingDelegate: class {
func back(tester: Bool)
}

class FirstViewController: UIViewController {
var name: String?
private let goToPost = ThirdViewController()

override func viewDidLoad() {
super.viewDidLoad()
goToPost.delegate = self
}
}
extension FirstViewController: CountingDelegate {
func back(tester: Bool) {
let checkvalue = tester
if checkvalue != nil {
let registerVC = self.storyboard?.instantiateViewController(identifier: "PostViewController")
self.navigationController?.pushViewController(registerVC!, animated: true)
}
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question