异步调用后读取 UISwitch 的状态
我有一个带有 UISwitch 的登录屏幕,让用户选择“记住我”,这样我就可以根据需要将他/她的凭据存储在钥匙链上。
仅当用户选择“记住我”并且服务器接受用户名/密码时才会发生这种情况。但是,当服务器回复时,我很难参考 UISwitch 的状态。令我惊讶的是,myUISwitch.on 的值为(null)。
NSLog (@"(Successful login. Value of UISwitch rememberMe: %@)", rememberMe.on);
我必须将此信息存储在临时布尔值中吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果为 null,则不是
on
属性,而是rememberMe
变量,该变量未设置。在 Interface Builder 或代码中正确连接它。另外,请确保始终从主线程访问 UIKit,即使用 PerformSelectorOnMainThread:
在此处输入代码
。If it is null, it is not the
on
property but therememberMe
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
.当你引用switch的时候视图还没有释放吗?
UISwitch
是否已被运行时释放?您什么时候尝试读取其状态?当您读取其状态时,控件是否仍在屏幕上?Is the view still not released by the time you refer to the switch? Is the
UISwitch
already released by the runtime? When did you attempt to read its state? Is the control still on the screen by the time you read its state?