好吧,所以我试图让用户翻动作弊模式开关时,它将禁用answerButton。我确实尝试将按钮设置为在底部附近禁用,但它看起来并没有做任何事情。我添加了print(“”)来查看它是否会在控制台中打印,但是没有打印。我不确定这里有什么问题。使用swift禁用其他视图控制器的按钮
我粘贴了下面的代码。
import Foundation
import UIKit
class SettingsController: UITableViewController {
@IBOutlet weak var cheatSwitch: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
cheatSwitch.isOn = UserDefaults.standard.bool(forKey: "switchState")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func saveSettings(_ sender: UISwitch) {
UserDefaults.standard.set(cheatSwitch.isOn, forKey: "switchState")
UserDefaults.standard.synchronize()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let mainView : ViewController = segue.destination as! ViewController
if cheatSwitch.isOn == true {
print("turn off button")
mainView.btnAnswer.isEnabled = false;
}
else {
print("turn on button")
mainView.btnAnswer.isEnabled = true;
}
}
}
您是否仔细检查了故事板中的链接? – scb998
是的按钮和链接工作。它只是不会禁用主视图上的按钮。 – winter4w
它是不是在控制台上打印一条打印语句?另外,没有'performSegue'的代码显示你如何移动到'ViewController'? –