views:

184

answers:

1

Hey, I'm a newbie to iPhone dev...

I want a boolean Variable which switches between YES and NO when I click on a UIButton. Really easy I think ?! But I weren't able to find anything. :(

Thx :) Sebastian

+1  A: 

The iPhone doesn't use toggle buttons because they're to difficult to use with a touch interface. It's too easy for a user to tap twice.

Instead you use a UISwitch control. You set up an action method just like a regular button and in the action method you check the UISwitch control's on property like so:

-(IBAction) switchChanged:(id) sender{
    if ([sender class] == [UISwitch class]) { //belt and suspenders
        myBooleanVar=sender.on;
    }
}

You can set up a toggle button but its a pain and will confuse users.

TechZen
Thanks you for your answer ! My button shows an check mark or an "X". When you are ready you tab on the "X", the "X" changes to the check mark and the BOOL turns from NO to YES. Thats what I want to do. But it musst be possible to re-tab the check mark so it becomes the "X" again and than the BOOL hast to be re-set to NO.Maybe my quistion wasn't asked too good :| sorry ...I don't thing that the UISwitch is the solution ? If I'm not mistaken ...THX Sebastian
Sebastian
The UISwitch is for just this type of ON/OFF, YES/NO use.
TechZen