Search code examples
iphoneasynchronousuiswitch

Reading the state of a UISwitch after an asynchronous call


I have a loging screen with a UISwitch for letting the user choose "remember me" so I can store his/her credentials on the key chain if desired.

This will only happen if the user has chosen "remember me" AND the server accepts the username/password. However, when the server replies, I have a hard time referring to the state of the UISwitch. The value of myUISwitch.on is, to my surprise (null).

NSLog (@"(Successful login. Value of UISwitch rememberMe: %@)", rememberMe.on);

Must I store this information in a temporary boolean?


Solution

  • If it is null, it is not the on property but the rememberMe variable, which is not set. Wire it up correctly in Interface Builder or in code.

    Also, make sure to access UIKit always from the main thread, i.e. use performSelectorOnMainThread:enter code here.