hi, m new to objective-c, i have made a application of login page in which i have used UISwitch to remember d login details if switch is in on mode. i have done with to remember the login details but problem is that how to use the switch on/off condition. Thanx in advance
+2
A:
You would add a conditional statement somewhere in your code depending on the switch's on
property. Let's say, for example, that you remember login details in a method called rememberLoginDetails
. What you would do is, when some action is triggered (the user leaves the login page, for example):
if([yourSwitch isOn]) {
[self rememberLoginDetails];
} else {
// Do nothing - switch is not on.
}
The important method here is the isOn
method for the UISwitch yourSwitch
. isOn
is the getter for the switch's on
property, which is a BOOL
property containing YES
if the switch is on, and NO
if it is not.
For more information, you can see the UISwitch class reference, specifically the part about isOn
.
Tim
2009-07-08 08:13:37
hi tim, i have used your code..but d problem is remain same. it is remembering d details in off condition too.
2009-07-08 09:13:24
In that case, it would help if you could edit your original question to include the code you're using.
Tim
2009-07-08 13:40:49
@Harita: I had the same problem.. I tried using a == TRUE afterwards and it still did not work. Then I went into interface builder, connected the switch to my IBOutlet var, and it worked :]
abelito
2010-07-11 22:23:55
A:
I believe the code needs to be this:
if([yourSwitch isOn] == YES) {
[self rememberLoginDetails];
} else {
// Do nothing - switch is not on.
}
Jay
2009-11-24 20:39:53
A:
This is another solution for that question.
if (switchValue.on == YES)
{
// Code...
}
else (switchValue.on == NO)
{
// Other code...
}
Nat Aguilar
2010-01-25 07:18:31
A:
The most easiest solution of all :)
if (switchValue.on) {
//Remember Login Details
}
else {
//Code something else
}
T. A.
2010-07-16 19:19:32