当我的切换行的行值发生变化时,我如何 enable/disable 我的模态?
How can I enable/disable my modal when the row value of my switch row changes?
我想activate/deactivate我的模式取决于我的开关行的当前值。
我有一个 SettingsViewController,用户可以在其中启用或禁用它:
class SettingsFormViewController : FormViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
form
+++ Section("Messages")
<<< SwitchRow("message_users") { row in
row.title = "Activate messages"
}.onChange { row in
row.title = (row.value ?? false) ? "Deactivate messages" : "Activate messages"
row.updateCell()
}
现在在我的 ReloadManager 中,我想检查该行是否已启用。如果它被启用,一个模式应该出现,如果没有它不应该:
class ReloadManager {
...
private func showModalFromSettings() {
let nav = UINavigationController()
let ctrl = MessageFormViewController()
ctrl.preferredContentSize = CGSize(width: 600, height: 400)
nav.pushViewController(ctrl, animated: true)
nav.modalPresentationStyle = .popover
UIApplication.shared.keyWindow?.rootViewController!.present(nav, animated: true, completion: nil)
nav.popoverPresentationController?.sourceView = UIApplication.shared.keyWindow?.rootViewController?.view
}
}
检查行是否启用然后将值传递给我的 ReloadManager 的最佳方法是什么?
提前致谢!
您可以使用 UserDefaults 来保存行的状态。
+++ Section("Messages")
<<< SwitchRow("message_users") { row in
row.title = "Activate messages"
}.onChange { row in
row.title = (row.value ?? false) ? "Deactivate messages" : "Activate
messages"
row.updateCell()
UserDefaults.standard.set(row.value ?? false, forKey: "RowStatus")
}
private func showModalFromSettings() {
let rowStatus = UserDefaults.standard.bool(forKey: "RowStatus")
if rowStatus {
//Do something when row enabled
} else {
//Do something when row disabled
}
let nav = UINavigationController()
let ctrl = MessageFormViewController()
ctrl.preferredContentSize = CGSize(width: 600, height: 400)
nav.pushViewController(ctrl, animated: true)
nav.modalPresentationStyle = .popover
UIApplication.shared.keyWindow?.rootViewController!.present(nav, animated: true, completion: nil)
nav.popoverPresentationController?.sourceView = UIApplication.shared.keyWindow?.rootViewController?.view
}
}
我想activate/deactivate我的模式取决于我的开关行的当前值。
我有一个 SettingsViewController,用户可以在其中启用或禁用它:
class SettingsFormViewController : FormViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
form
+++ Section("Messages")
<<< SwitchRow("message_users") { row in
row.title = "Activate messages"
}.onChange { row in
row.title = (row.value ?? false) ? "Deactivate messages" : "Activate messages"
row.updateCell()
}
现在在我的 ReloadManager 中,我想检查该行是否已启用。如果它被启用,一个模式应该出现,如果没有它不应该:
class ReloadManager {
...
private func showModalFromSettings() {
let nav = UINavigationController()
let ctrl = MessageFormViewController()
ctrl.preferredContentSize = CGSize(width: 600, height: 400)
nav.pushViewController(ctrl, animated: true)
nav.modalPresentationStyle = .popover
UIApplication.shared.keyWindow?.rootViewController!.present(nav, animated: true, completion: nil)
nav.popoverPresentationController?.sourceView = UIApplication.shared.keyWindow?.rootViewController?.view
}
}
检查行是否启用然后将值传递给我的 ReloadManager 的最佳方法是什么? 提前致谢!
您可以使用 UserDefaults 来保存行的状态。
+++ Section("Messages")
<<< SwitchRow("message_users") { row in
row.title = "Activate messages"
}.onChange { row in
row.title = (row.value ?? false) ? "Deactivate messages" : "Activate
messages"
row.updateCell()
UserDefaults.standard.set(row.value ?? false, forKey: "RowStatus")
}
private func showModalFromSettings() {
let rowStatus = UserDefaults.standard.bool(forKey: "RowStatus")
if rowStatus {
//Do something when row enabled
} else {
//Do something when row disabled
}
let nav = UINavigationController()
let ctrl = MessageFormViewController()
ctrl.preferredContentSize = CGSize(width: 600, height: 400)
nav.pushViewController(ctrl, animated: true)
nav.modalPresentationStyle = .popover
UIApplication.shared.keyWindow?.rootViewController!.present(nav, animated: true, completion: nil)
nav.popoverPresentationController?.sourceView = UIApplication.shared.keyWindow?.rootViewController?.view
}
}