如何通过拨动开关应用设置?
可能的重复:
谁能告诉我如何使用 switch 吗?
嗨,我有两个视图
第一个视图包含主要功能,第二个视图用于让用户更改第一个视图上的设置。
我在第二个视图中插入了一个开关,以让用户更改第一个视图上的设置
我有两个问题,如何使用开关为值设置“是”和“否”?然后根据该值 第一个视图会有不同的反应吗?
PS 我用导航方法更改视图,而不是添加子视图
提前感谢
让我说我有以下代码
First View.m
- (IBAction) addValue:(id)sender
{
aValue ++;
}
//the following will react according to the setting on second view
If (????//Don't know what to put here to represent the switch is ON or OFF)
{ //whatever action}
else
{//whatever action}
secondary view.h
@interface
//declaration of the switch
- (IBAction) changeMode:(id)sender
@end
secondary view.m
-(IBAction) changeMode:(id)sender
{
//What to put here to switch ON and OFF ??
}
Possible Duplicate:
can anyone tell me how to use switch ?
Hi I have two view
the first view contains the main function and the second view is used to let the user change the setting on the first view.
I have insert a switch in second view to let user change a setting on the first view
I have two questions, how to use switch to set YES and NO for a value? and then, base on that value
the first view will respond differently?
P.S. I change the view with navigation method , not add subview
Thanks in advance
lets say I have the following code
First View.m
- (IBAction) addValue:(id)sender
{
aValue ++;
}
//the following will react according to the setting on second view
If (????//Don't know what to put here to represent the switch is ON or OFF)
{ //whatever action}
else
{//whatever action}
second view.h
@interface
//declaration of the switch
- (IBAction) changeMode:(id)sender
@end
second view.m
-(IBAction) changeMode:(id)sender
{
//What to put here to switch ON and OFF ??
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你可以这样做:
这里我假设 mySwitch 是 UISwitch 的一个实例。将开关值存储到 NSUserDefaults 是一个好主意,以便您可以从另一个视图检索它。
这是存储值的方式:
这是检索值的方式:
You can do this:
Here I assume mySwitch is an instance of UISwitch. It is a good idea to store switch value to NSUserDefaults so that you can retrieve it from another view.
This is how you store the value:
This is how you retrieve the value: