Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当应用程序进入后台时,我想将开关设置为关闭。我正在尝试使用以下代码来做到这一点。它不起作用:(当我恢复应用程序时,屏幕上的动画开关仍然“打开”。我该如何解决这个问题?
- (void)applicationWillResignActive:(UIApplication *)application { [registrationSwitch setOn:NO animated:YES]; }
您需要在 userDefaults 中设置该值。添加一个布尔检查,如:
if (userDefaultBool == 1){ registrationSwitch setOn } else{ registration setOff }
把它放在你的viewDidLoad
viewDidLoad