views:

1471

answers:

4

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
hi tim, i have used your code..but d problem is remain same. it is remembering d details in off condition too.
In that case, it would help if you could edit your original question to include the code you're using.
Tim
@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
A: 

I believe the code needs to be this:

if([yourSwitch isOn] == YES) {
    [self rememberLoginDetails];
} else {
    // Do nothing - switch is not on.
}
Jay
A: 

This is another solution for that question.

if (switchValue.on == YES)
{
    // Code...
}
else (switchValue.on == NO)
{
    // Other code... 
}
Nat Aguilar
A: 

The most easiest solution of all :)

if (switchValue.on) {

//Remember Login Details

}

else {

//Code something else 

}

T. A.